2 * Copyright (C) Volition, Inc. 1999. All rights reserved.
4 * All source code herein is the property of Volition, Inc. You may not sell
5 * or otherwise commercially exploit the source or things you created based on the
12 #include "osregistry.h"
13 #include "multi_options.h"
14 #include "gamesequence.h"
18 #include "stand_server.h"
19 #include "multi_pmsg.h"
20 #include "multi_endgame.h"
21 #include "multimsgs.h"
22 #include "multiutil.h"
23 #include "freespace.h"
24 #include "missiongoals.h"
26 #include "multi_kick.h"
27 #include "multi_fstracker.h"
28 #include "osregistry.h"
29 #include "standalone_html.h"
31 #include <libwebsockets.h>
39 std::string debug_txt;
40 std::string popup_title;
41 std::string popup_field1;
42 std::string popup_field2;
44 std::string active_player;
47 static std_state Standalone_state;
49 static std::list<std::string> Standalone_send_buf;
52 #define STANDALONE_MAX_BAN 50
53 static std::vector<std::string> Standalone_ban_list;
55 #define STD_STATS_UPDATE_TIME 500 // ms between updating player stats
56 #define STD_NG_UPDATE_TIME 1500 // ms between updating netgame information
57 #define STD_PING_UPDATE_TIME 1000 // ms between updating pings
58 #define STD_FPS_UPDATE_TIME 250 // ms between fps updates
60 static int Standalone_stats_stamp = -1;
61 static int Standalone_ng_stamp = -1;
62 static int Standalone_ping_stamp = -1;
63 static int Standalone_fps_stamp = -1;
65 static lws_context *stand_context = NULL;
67 static int startup_reset_stamp;
68 static struct lws *active_wsi = NULL;
71 static int callback_http(struct lws *wsi, enum lws_callback_reasons reason, void *user, void *in, size_t len)
73 unsigned char buf[LWS_SEND_BUFFER_PRE_PADDING + standalone_html_len + LWS_SEND_BUFFER_POST_PADDING];
74 unsigned char *p = &buf[LWS_SEND_BUFFER_PRE_PADDING];
75 unsigned char *start = p;
76 unsigned char *end = p + standalone_html_len;
77 bool try_reuse = false;
80 static unsigned int sent = 0;
83 case LWS_CALLBACK_HTTP: {
85 lws_return_http_status(wsi, HTTP_STATUS_BAD_REQUEST, NULL);
91 // no favicon so return 404
92 if ( in && !SDL_strcmp((const char *)in, "/favicon.ico") ) {
93 lws_return_http_status(wsi, HTTP_STATUS_NOT_FOUND, NULL);
99 // any other request will get our basic html ...
102 FILE *html = fopen("./standalone.html", "rb");
107 rval = lws_serve_http_file(wsi, "./standalone.html", "text/html", NULL, 0);
109 if ( (rval < 0) || ((rval > 0) && lws_http_transaction_completed(wsi)) ) {
110 // error or can't reuse connection, close the socket
116 if ( lws_add_http_header_status(wsi, 200, &p, end) ) {
120 if ( lws_add_http_header_by_token(wsi, WSI_TOKEN_HTTP_SERVER, (unsigned char *)"libwebsockets", 13, &p, end) ) {
124 if ( lws_add_http_header_by_token(wsi, WSI_TOKEN_HTTP_CONTENT_TYPE, (unsigned char *)"text/html", 9, &p, end) ) {
128 if ( lws_add_http_header_by_token(wsi, WSI_TOKEN_HTTP_CONTENT_ENCODING, (unsigned char *)"gzip", 4, &p, end) ) {
132 if ( lws_add_http_header_content_length(wsi, standalone_html_len, &p, end) ) {
136 if ( lws_finalize_http_header(wsi, &p, end) ) {
140 rval = lws_write(wsi, start, p - start, LWS_WRITE_HTTP_HEADERS);
142 if (rval != (p - start)) {
148 lws_callback_on_writable(wsi);
154 case LWS_CALLBACK_HTTP_BODY_COMPLETION: {
155 lws_return_http_status(wsi, HTTP_STATUS_OK, NULL);
161 case LWS_CALLBACK_HTTP_FILE_COMPLETION: {
167 case LWS_CALLBACK_HTTP_WRITEABLE: {
168 while ( !lws_send_pipe_choked(wsi) && (sent < standalone_html_len) ) {
169 size = standalone_html_len - sent;
171 int pwa = lws_get_peer_write_allowance(wsi);
174 lws_callback_on_writable(wsi);
179 if ( (pwa != -1) && (pwa < size) ) {
183 memcpy(p, standalone_html + sent, size);
185 rval = lws_write(wsi, p, size, LWS_WRITE_HTTP);
192 // while still active, extent timeout
193 lws_set_timeout(wsi, PENDING_TIMEOUT_HTTP_CONTENT, 5);
209 if (lws_http_transaction_completed(wsi)) {
217 static int callback_standalone(struct lws *wsi, enum lws_callback_reasons reason, void *user, void *in, size_t len)
219 #define MAX_BUF_SIZE 1024
220 unsigned char buf[LWS_SEND_BUFFER_PRE_PADDING + MAX_BUF_SIZE + LWS_SEND_BUFFER_POST_PADDING];
221 unsigned char *p = &buf[LWS_SEND_BUFFER_PRE_PADDING];
226 case LWS_CALLBACK_ESTABLISHED: {
229 if ( timestamp_elapsed(startup_reset_stamp) ) {
230 std_reset_standalone_gui();
236 case LWS_CALLBACK_CLOSED: {
242 case LWS_CALLBACK_FILTER_PROTOCOL_CONNECTION: {
250 case LWS_CALLBACK_SERVER_WRITEABLE: {
251 while ( !Standalone_send_buf.empty() ) {
252 size = SDL_strlcpy((char *)p, Standalone_send_buf.front().c_str(), MAX_BUF_SIZE);
254 rval = lws_write(wsi, p, size, LWS_WRITE_TEXT);
257 lwsl_err("ERROR sending buffer!\n");
258 lws_close_reason(wsi, LWS_CLOSE_STATUS_UNEXPECTED_CONDITION, (unsigned char *)"write error", 11);
263 Standalone_send_buf.pop_front();
265 if ( lws_send_pipe_choked(wsi) ) {
266 lws_callback_on_writable(wsi);
275 case LWS_CALLBACK_RECEIVE: {
276 if (in != NULL && len > 0) {
277 const char *msg = (const char *)in;
280 if ( !SDL_strcmp(msg, "shutdown") ) {
281 gameseq_post_event(GS_EVENT_QUIT_GAME);
282 lws_close_reason(wsi, LWS_CLOSE_STATUS_GOINGAWAY, (unsigned char *)"shutdown", 8);
287 if ( !SDL_strcmp(msg, "reset") ) {
288 multi_quit_game(PROMPT_NONE);
289 std_reset_standalone_gui();
297 if ( !SDL_strncmp(msg+2, "name ", 5) ) {
298 SDL_strlcpy(Netgame.name, msg+7, SDL_arraysize(Netgame.name));
299 SDL_strlcpy(Multi_options_g.std_pname, Netgame.name, SDL_arraysize(Multi_options_g.std_pname));
300 } else if ( !SDL_strncmp(msg+2, "pass ", 5) ) {
301 SDL_strlcpy(Multi_options_g.std_passwd, msg+7, SDL_arraysize(Multi_options_g.std_passwd));
302 } else if ( !SDL_strncmp(msg+2, "kick ", 5) ) {
305 for (int i = 0; i < MAX_PLAYERS; i++) {
306 if ( MULTI_CONNECTED(Net_players[i]) ) {
307 psnet_addr_to_string(ip_string, SDL_arraysize(ip_string), &Net_players[i].p_info.addr);
309 if ( !SDL_strcmp(msg+7, ip_string) ) {
310 multi_kick_player(i, 0);
320 else if (mtype == 'M') {
322 if ( !SDL_strncmp(msg+2, "fps ", 4) ) {
323 int fps = SDL_atoi(msg+6);
326 Multi_options_g.std_framecap = fps;
331 else if (mtype == 'P') {
333 if ( !SDL_strncmp(msg+2, "info ", 5) ) {
336 for (i = 0; i < MAX_PLAYERS; i++) {
337 net_player *np = &Net_players[i];
339 if ( MULTI_CONNECTED((*np)) && (Net_player != np) ) {
340 if ( !SDL_strcmp(msg+7, np->player->callsign) ) {
341 Standalone_state.active_player = msg+7;
342 std_pinfo_display_player_info(np);
349 if (i == MAX_PLAYERS) {
350 Standalone_state.active_player.clear();
356 else if (mtype == 'G') {
358 if ( !SDL_strncmp(msg+2, "smsg ", 5) ) {
361 SDL_strlcpy(txt, msg+7, SDL_arraysize(txt));
363 if (SDL_strlen(txt) > 0) {
364 send_game_chat_packet(Net_player, txt, MULTI_MSG_ALL, NULL);
366 std_add_chat_text(txt, MY_NET_PLAYER_NUM, 1);
368 } else if ( !SDL_strcmp(msg+2, "mrefresh") ) {
369 if (MULTI_IS_TRACKER_GAME) {
370 cf_delete(MULTI_VALID_MISSION_FILE, CF_TYPE_DATA);
372 multi_update_valid_missions();
389 static struct lws_protocols stand_protocols[] = {
411 static void std_lws_logger(int level, const char *line)
413 if (level & (LLL_WARN|LLL_ERR)) {
414 mprintf(("STD: %s", line));
415 } else if (level & LLL_NOTICE) {
416 nprintf(("lws", "STD: %s", line));
422 static void std_add_ws_message(const char *id, const char *val)
426 // if no client, and startup stamp elapsed, then don't add more messages
427 if ( (active_wsi == NULL) && timestamp_elapsed(startup_reset_stamp) ) {
437 Standalone_send_buf.push_back(msg);
440 void std_deinit_standalone()
443 lws_cancel_service(stand_context);
444 lws_context_destroy(stand_context);
445 stand_context = NULL;
449 void std_init_standalone()
451 struct lws_context_creation_info info;
459 // basic security measure for admin interface
460 // "1" bind to loopback iface only *default*
461 // "0" bind to any/all
462 // any other value should be ip or iface name to bind
463 // (invalid values will trigger error)
465 const char *stand_iface = os_config_read_string("Network", "RestrictStandAdmin", "1");
467 if ( !SDL_strcmp(stand_iface, "1") ) {
468 info.iface = "127.0.0.1";
469 } else if ( !SDL_strcmp(stand_iface, "0") ) {
472 info.iface = stand_iface;
475 info.port = Multi_options_g.port;
477 info.protocols = stand_protocols;
482 lws_set_log_level(LLL_ERR|LLL_WARN|LLL_NOTICE, std_lws_logger);
484 stand_context = lws_create_context(&info);
486 if (stand_context == NULL) {
487 Error(LOCATION, "Unable to initialize standalone server!");
490 atexit(std_deinit_standalone);
492 // turn off all sound and music
493 Cmdline_freespace_no_sound = 1;
494 Cmdline_freespace_no_music = 1;
497 SDL_snprintf(title, SDL_arraysize(title), "%s %d.%02d.%02d", XSTR("FreeSpace Standalone", 935), FS_VERSION_MAJOR, FS_VERSION_MINOR, FS_VERSION_BUILD);
498 Standalone_state.title = title;
500 // connections > 5 sec after startup should get gui reset
501 startup_reset_stamp = timestamp(5000);
503 std_reset_standalone_gui();
505 std_multi_update_netgame_info_controls();
508 static void std_update_ping_all()
510 std::string ping_upd;
513 for (int i = 0, idx = 0; i < MAX_PLAYERS; i++) {
514 net_player *np = &Net_players[i];
516 if ( MULTI_CONNECTED((*np)) && (Net_player != np) ) {
517 if (np->s_info.ping.ping_avg > -1) {
518 if (np->s_info.ping.ping_avg >= 1000) {
519 SDL_snprintf(ping_str, SDL_arraysize(ping_str), "%s", XSTR("> 1 sec", 914));
521 SDL_snprintf(ping_str, SDL_arraysize(ping_str), "%d%s", np->s_info.ping.ping_avg, XSTR(" ms", 915));
527 // append separator if not first
529 ping_upd.append(",");
532 ping_upd.append(ping_str);
536 if ( !ping_upd.empty() ) {
537 std_add_ws_message("S:ping ", ping_upd.c_str());
541 static void std_update_connections()
543 std::string conn_str;
546 conn_str.reserve(1024);
548 for (int i = 0, idx = 0; i < MAX_PLAYERS; i++) {
549 net_player *np = &Net_players[i];
551 if ( MULTI_CONNECTED((*np)) && (Net_player != np) ) {
552 // append seperator if not first
554 conn_str.append(";");
557 conn_str.append(np->player->callsign);
558 conn_str.append(",");
560 psnet_addr_to_string(ip_address, SDL_arraysize(ip_address), &np->p_info.addr);
561 conn_str.append(ip_address);
565 SDL_assert(conn_str.length() < 1024);
567 if ( !conn_str.empty() ) {
568 std_add_ws_message("S:conn ", conn_str.c_str());
572 void std_do_gui_frame()
574 // maybe update selected player stats
575 if ( ((Standalone_stats_stamp == -1) || timestamp_elapsed(Standalone_stats_stamp)) && !Standalone_state.active_player.empty() ) {
576 Standalone_stats_stamp = timestamp(STD_STATS_UPDATE_TIME);
578 for (int i = 0; i < MAX_PLAYERS; i++) {
579 net_player *np = &Net_players[i];
581 if ( MULTI_CONNECTED((*np)) && (Net_player != np) ) {
582 if ( !SDL_strcmp(Standalone_state.active_player.c_str(), np->player->callsign) ) {
583 std_pinfo_display_player_info(np);
591 // maybe update netgame info
592 if ( (Standalone_ng_stamp == -1) || timestamp_elapsed(Standalone_ng_stamp) ) {
593 Standalone_ng_stamp = timestamp(STD_NG_UPDATE_TIME);
595 std_multi_update_netgame_info_controls();
598 // update connection ping times
599 if ( ((Standalone_ping_stamp == -1) || timestamp_elapsed(Standalone_ping_stamp)) ) {
600 Standalone_ping_stamp = timestamp(STD_PING_UPDATE_TIME);
602 std_update_ping_all();
605 if ( !Standalone_send_buf.empty() ) {
606 lws_callback_on_writable_all_protocol(stand_context, &stand_protocols[1]);
609 lws_service(stand_context, 0);
612 void std_debug_set_standalone_state_string(const char *str)
614 Standalone_state.debug_txt = str;
616 std_add_ws_message("D:", str);
619 void std_connect_set_gamename(const char *name)
622 // if a permanent name exists, use that instead of the default
623 if ( SDL_strlen(Multi_options_g.std_pname) ) {
624 SDL_strlcpy(Netgame.name, Multi_options_g.std_pname, SDL_arraysize(Netgame.name));
626 SDL_strlcpy(Netgame.name, XSTR("Standalone Server", 916), SDL_arraysize(Netgame.name));
629 SDL_strlcpy(Netgame.name, name, SDL_arraysize(Netgame.name));
632 std_add_ws_message("S:name ", Netgame.name);
635 int std_connect_set_connect_count()
639 for (int i = 0; i < MAX_PLAYERS; i++) {
640 if (MULTI_CONNECTED(Net_players[i]) && (Net_player != &Net_players[i]) ) {
648 void std_add_player(net_player *p)
650 std_update_connections();
652 // clear active player, client should reset if needed
653 Standalone_state.active_player.clear();
655 // check to see if this guy is the host
656 std_connect_set_host_connect_status();
659 int std_remove_player(net_player *p)
663 std_update_connections();
665 // clear active player, client should reset if needed
666 Standalone_state.active_player.clear();
668 // update the host connect count
669 std_connect_set_host_connect_status();
671 // update the currently connected players
672 count = std_connect_set_connect_count();
675 multi_quit_game(PROMPT_NONE);
682 void std_update_player_ping(net_player *p)
686 void std_pinfo_display_player_info(net_player *p)
694 pinfo.append(Ship_info[p->p_info.ship_class].name);
698 if (p->s_info.ping.ping_avg > 1000) {
699 SDL_snprintf(sml_ping, SDL_arraysize(sml_ping), "%s", XSTR("> 1 sec", 914));
701 SDL_snprintf(sml_ping, SDL_arraysize(sml_ping), "%d%s", p->s_info.ping.ping_avg, XSTR(" ms", 915));
704 pinfo.append(sml_ping);
707 scoring_struct *ptr = &p->player->stats;
710 SDL_snprintf(sml_ping, SDL_arraysize(sml_ping), "%d", ptr->p_shots_fired);
711 pinfo.append(sml_ping);
713 SDL_snprintf(sml_ping, SDL_arraysize(sml_ping), "%d", ptr->p_shots_hit);
714 pinfo.append(sml_ping);
716 SDL_snprintf(sml_ping, SDL_arraysize(sml_ping), "%d", ptr->p_bonehead_hits);
717 pinfo.append(sml_ping);
719 SDL_snprintf(sml_ping, SDL_arraysize(sml_ping), "%d", ptr->p_shots_fired ? (int)(100.0f * ((float)ptr->p_shots_hit / (float)ptr->p_shots_fired)) : 0);
720 pinfo.append(sml_ping);
722 SDL_snprintf(sml_ping, SDL_arraysize(sml_ping), "%d", ptr->p_shots_fired ? (int)(100.0f * ((float)ptr->p_bonehead_hits / (float)ptr->p_shots_fired)) : 0);
723 pinfo.append(sml_ping);
725 SDL_snprintf(sml_ping, SDL_arraysize(sml_ping), "%d", ptr->s_shots_fired);
726 pinfo.append(sml_ping);
728 SDL_snprintf(sml_ping, SDL_arraysize(sml_ping), "%d", ptr->s_shots_hit);
729 pinfo.append(sml_ping);
731 SDL_snprintf(sml_ping, SDL_arraysize(sml_ping), "%d", ptr->s_bonehead_hits);
732 pinfo.append(sml_ping);
734 SDL_snprintf(sml_ping, SDL_arraysize(sml_ping), "%d", ptr->s_shots_fired ? (int)(100.0f * ((float)ptr->s_shots_hit / (float)ptr->s_shots_fired)) : 0);
735 pinfo.append(sml_ping);
737 SDL_snprintf(sml_ping, SDL_arraysize(sml_ping), "%d", ptr->s_shots_fired ? (int)(100.0f * ((float)ptr->s_bonehead_hits / (float)ptr->s_shots_fired)) : 0);
738 pinfo.append(sml_ping);
740 SDL_snprintf(sml_ping, SDL_arraysize(sml_ping), "%d", ptr->assists);
741 pinfo.append(sml_ping);
742 pinfo.append(";"); // <- end of block
745 SDL_snprintf(sml_ping, SDL_arraysize(sml_ping), "%d", ptr->mp_shots_fired);
746 pinfo.append(sml_ping);
748 SDL_snprintf(sml_ping, SDL_arraysize(sml_ping), "%d", ptr->mp_shots_hit);
749 pinfo.append(sml_ping);
751 SDL_snprintf(sml_ping, SDL_arraysize(sml_ping), "%d", ptr->mp_bonehead_hits);
752 pinfo.append(sml_ping);
754 SDL_snprintf(sml_ping, SDL_arraysize(sml_ping), "%d", ptr->mp_shots_fired ? (int)(100.0f * ((float)ptr->mp_shots_hit / (float)ptr->mp_shots_fired)) : 0);
755 pinfo.append(sml_ping);
757 SDL_snprintf(sml_ping, SDL_arraysize(sml_ping), "%d", ptr->mp_shots_fired ? (int)(100.0f * ((float)ptr->mp_bonehead_hits / (float)ptr->mp_shots_fired)) : 0);
758 pinfo.append(sml_ping);
760 SDL_snprintf(sml_ping, SDL_arraysize(sml_ping), "%d", ptr->ms_shots_fired);
761 pinfo.append(sml_ping);
763 SDL_snprintf(sml_ping, SDL_arraysize(sml_ping), "%d", ptr->ms_shots_hit);
764 pinfo.append(sml_ping);
766 SDL_snprintf(sml_ping, SDL_arraysize(sml_ping), "%d", ptr->ms_bonehead_hits);
767 pinfo.append(sml_ping);
769 SDL_snprintf(sml_ping, SDL_arraysize(sml_ping), "%d", ptr->ms_shots_fired ? (int)(100.0f * ((float)ptr->ms_shots_hit / (float)ptr->ms_shots_fired)) : 0);
770 pinfo.append(sml_ping);
772 SDL_snprintf(sml_ping, SDL_arraysize(sml_ping), "%d", ptr->ms_shots_fired ? (int)(100.0f * ((float)ptr->ms_bonehead_hits / (float)ptr->ms_shots_fired)) : 0);
773 pinfo.append(sml_ping);
775 SDL_snprintf(sml_ping, SDL_arraysize(sml_ping), "%d", ptr->m_assists);
776 pinfo.append(sml_ping);
778 std_add_ws_message("P:info ", pinfo.c_str());
781 void std_add_chat_text(const char *text, int player_index, int add_id)
786 if ( (player_index < 0) || (player_index >= MAX_PLAYERS) ) {
790 // format the chat text nicely
792 if ( MULTI_STANDALONE(Net_players[player_index]) ) {
793 SDL_snprintf(id, SDL_arraysize(id), XSTR("<SERVER> %s", 924), "");
795 SDL_snprintf(id, SDL_arraysize(id), "%s: ", Net_players[player_index].player->callsign);
804 std_add_ws_message("G:mesg ", msg.c_str());
807 void std_reset_timestamps()
809 // reset the stats update stamp
810 Standalone_stats_stamp = timestamp(STD_STATS_UPDATE_TIME);
812 // reset the netgame controls update timestamp
813 Standalone_ng_stamp = timestamp(STD_NG_UPDATE_TIME);
815 // reset the ping update stamp
816 Standalone_ping_stamp = timestamp(STD_PING_UPDATE_TIME);
818 // reset fps update stamp
819 Standalone_fps_stamp = timestamp(STD_FPS_UPDATE_TIME);
822 void std_add_ban(const char *name)
824 if ( (name == NULL) || !SDL_strlen(name) ) {
828 if (Standalone_ban_list.size() >= STANDALONE_MAX_BAN) {
832 Standalone_ban_list.push_back(name);
835 int std_player_is_banned(const char *name)
837 if ( Standalone_ban_list.empty() ) {
841 for (size_t i = 0; i < Standalone_ban_list.size(); i++) {
842 if ( !SDL_strcasecmp(name, Standalone_ban_list[i].c_str()) ) {
850 int std_is_host_passwd()
852 return (SDL_strlen(Multi_options_g.std_passwd) > 0) ? 1 : 0;
855 void std_multi_set_standalone_mission_name(const char *mission_name)
857 std_add_ws_message("M:name ", mission_name);
860 void std_multi_set_standalone_missiontime(float mission_time)
864 fix m_time = fl2f(mission_time);
866 // format the time string and set the text
867 game_format_time(m_time, timestr, SDL_arraysize(timestr));
868 SDL_snprintf(txt, SDL_arraysize(txt), "%s : %.1f", timestr, mission_time);
870 std_add_ws_message("M:time ", txt);
873 void std_multi_update_netgame_info_controls()
877 SDL_snprintf(nginfo, SDL_arraysize(nginfo), "%d,%d,%d,%d", Netgame.max_players, Netgame.options.max_observers, Netgame.security, Netgame.respawn);
879 std_add_ws_message("M:info ", nginfo);
882 void std_set_standalone_fps(float fps)
884 if ( (Standalone_fps_stamp == -1) || timestamp_elapsed(Standalone_fps_stamp) ) {
885 Standalone_fps_stamp = timestamp(STD_FPS_UPDATE_TIME);
889 SDL_snprintf(rfps, SDL_arraysize(rfps), "%.1f", fps);
891 std_add_ws_message("M:rfps ", rfps);
895 void std_multi_setup_goal_tree()
897 std::string mission_goals;
899 std::string secondary;
903 for (int i = 0; i < Num_goals; i++) {
904 switch (Mission_goals[i].satisfied) {
910 case GOAL_COMPLETE: {
915 case GOAL_INCOMPLETE:
922 switch (Mission_goals[i].type & GOAL_TYPE_MASK) {
924 primary.append(status);
925 primary.append(Mission_goals[i].name);
931 case SECONDARY_GOAL: {
932 secondary.append(status);
933 secondary.append(Mission_goals[i].name);
934 secondary.append(",");
940 bonus.append(status);
941 bonus.append(Mission_goals[i].name);
952 if ( primary.empty() ) {
953 mission_goals.append("i none");
955 mission_goals.append(primary.substr(0, primary.size()-1));
958 mission_goals.append(";");
960 if ( secondary.empty() ) {
961 mission_goals.append("i none");
963 mission_goals.append(secondary.substr(0, secondary.size()-1));
966 mission_goals.append(";");
968 if ( bonus.empty() ) {
969 mission_goals.append("i none");
971 mission_goals.append(bonus.substr(0, bonus.size()-1));
974 std_add_ws_message("M:goal ", mission_goals.c_str());
977 void std_multi_add_goals()
979 std_multi_setup_goal_tree();
982 void std_multi_update_goals()
984 std_multi_setup_goal_tree();
987 void std_reset_standalone_gui()
989 Standalone_send_buf.clear();
991 std_add_ws_message("reset", NULL);
993 std_add_ws_message("T:", Standalone_state.title.c_str());
994 std_add_ws_message("D:", Standalone_state.debug_txt.c_str());
996 std_add_ws_message("S:name ", Netgame.name);
997 std_add_ws_message("S:pass ", Multi_options_g.std_passwd);
999 std_update_connections();
1000 std_set_standalone_fps(0.0f);
1001 std_multi_set_standalone_missiontime(0.0f);
1002 std_multi_update_netgame_info_controls();
1004 Standalone_fps_stamp = -1;
1005 Standalone_ng_stamp = -1;
1006 Standalone_ping_stamp = -1;
1007 Standalone_stats_stamp = -1;
1009 Standalone_state.active_player.clear();
1013 void std_create_gen_dialog(const char *title)
1015 Standalone_state.popup_title = title;
1017 Standalone_state.popup_field1 = "";
1018 Standalone_state.popup_field2 = "";
1021 void std_destroy_gen_dialog()
1023 std_add_ws_message("popup ", NULL);
1026 void std_gen_set_text(const char *str, int field_num)
1028 std::string popup_str;
1030 switch (field_num) {
1032 Standalone_state.popup_title = str;
1036 Standalone_state.popup_field1 = str;
1040 Standalone_state.popup_field2 = str;
1047 popup_str.append(Standalone_state.popup_title);
1048 popup_str.append(";");
1049 popup_str.append(Standalone_state.popup_field1);
1050 popup_str.append(";");
1051 popup_str.append(Standalone_state.popup_field2);
1053 std_add_ws_message("popup ", popup_str.c_str());
1055 // force ws write since do_frame() may not happen until popup is done
1056 lws_callback_on_writable_all_protocol(stand_context, &stand_protocols[1]);
1057 lws_service(stand_context, 0);
1060 void std_tracker_notify_login_fail()
1065 void std_tracker_login()
1067 if ( !Multi_options_g.pxo ) {
1071 multi_fs_tracker_init();
1073 if ( !multi_fs_tracker_inited() ) {
1074 std_tracker_notify_login_fail();
1078 multi_fs_tracker_login_freespace();
1081 void std_connect_set_host_connect_status()