From 0aa6319da1795a2a9472af0c4c0ca66ae47267c1 Mon Sep 17 00:00:00 2001 From: cib Date: Fri, 22 Jun 2012 08:41:00 -0700 Subject: [PATCH 01/15] Began work on a DLL for communicating with other processes through sockets. --- DLLSocket/DLLSocket.cbp | 50 ++++++++++++++++ DLLSocket/main.cpp | 124 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 174 insertions(+) create mode 100644 DLLSocket/DLLSocket.cbp create mode 100644 DLLSocket/main.cpp diff --git a/DLLSocket/DLLSocket.cbp b/DLLSocket/DLLSocket.cbp new file mode 100644 index 00000000000..6415a5ebd67 --- /dev/null +++ b/DLLSocket/DLLSocket.cbp @@ -0,0 +1,50 @@ + + + + + + diff --git a/DLLSocket/main.cpp b/DLLSocket/main.cpp new file mode 100644 index 00000000000..d5b278593a5 --- /dev/null +++ b/DLLSocket/main.cpp @@ -0,0 +1,124 @@ +// OS-specific networking includes +// ------------------------------- +#ifdef __WIN32 + #include + typedef int socklen_t; +#else + extern "C" { + #include + #include + #include + #include + #include + #include + } + + typedef int SOCKET; + typedef sockaddr_in SOCKADDR_IN; + typedef sockaddr SOCKADDR; + #define SOCKET_ERROR -1 +#endif + +// Socket used for all communications +SOCKET sock; + +// Address of the remote server +SOCKADDR_IN addr; + +// Buffer used to return dynamic strings to the caller +#define BUFFER_SIZE 1024 +char return_buffer[BUFFER_SIZE]; + +// exposed functions +// ------------------------------ + +const char* SUCCESS = "1\0"; // string representing success + +// arg1: ip(in the xx.xx.xx.xx format) +// arg2: port(a short) +// return: NULL on failure, SUCCESS otherwise +extern "C" const char* establish_connection(int n, char *v[]) +{ + // extract args + // ------------ + if(n < 2) return 0; + const char* ip = v[0]; + const char* port_s = v[1]; + unsigned short port = atoi(port_s); + + // set up network stuff + // -------------------- + #ifdef __WIN32 + WSADATA wsa; + WSAStartup(MAKEWORD(2,0),&wsa); + #endif + sock = socket(AF_INET,SOCK_DGRAM,0); + + // make the socket non-blocking + // ---------------------------- + #ifdef __WIN32 + unsigned long iMode=1; + ioctlsocket(sock,FIONBIO,&iMode); + #else + fcntl(sock, F_SETFL, O_NONBLOCK); + #endif + + // establish a connection to the server + // ------------------------------------ + memset(&addr,0,sizeof(SOCKADDR_IN)); + addr.sin_family=AF_INET; + addr.sin_port=htons(port); + + // convert the string representation of the ip to a byte representation + addr.sin_addr.s_addr=inet_addr(ip); + + return SUCCESS; +} + +// arg1: string message to send +// return: NULL on failure, SUCCESS otherwise +extern "C" const char* send_message(int n, char *v[]) +{ + // extract the args + const char* msg = v[1]; + + // send the message + int rc = sendto(sock,msg,strlen(msg),0,(SOCKADDR*)&addr,sizeof(SOCKADDR)); + + // check for errors + if (rc != -1) { + return SUCCESS; + } + else { + return 0; + } +} + +// no args +// return: message if any received, NULL otherwise +extern "C" const char* recv_message(int n, char *v[]) +{ + SOCKADDR_IN sender; // we will store the sender address here + + socklen_t sender_byte_length = sizeof(sender); + + // Try receiving messages until we receive one that's valid, or there are no more messages + while(1) { + int rc = recvfrom(sock, return_buffer, BUFFER_SIZE,0,(SOCKADDR*) &sender,&sender_byte_length); + if(rc > 0) { + // we could read something + + if(sender.sin_addr.s_addr != addr.sin_addr.s_addr) { + continue; // not our connection, ignore and try again + } else { + return_buffer[rc] = '0'; // 0-terminate the string + return return_buffer; + } + } + else { + break; // no more messages, stop trying to receive + } + } + + return 0; +} From ee5a8ec71920bb90928a3a42fa2ab9105a5666d2 Mon Sep 17 00:00:00 2001 From: cib Date: Fri, 22 Jun 2012 00:50:31 -0700 Subject: [PATCH 02/15] Added a sample python file to interact with the BYOND socket interface. --- DLLSocket/server_controller.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 DLLSocket/server_controller.py diff --git a/DLLSocket/server_controller.py b/DLLSocket/server_controller.py new file mode 100644 index 00000000000..d1eb09cb02f --- /dev/null +++ b/DLLSocket/server_controller.py @@ -0,0 +1,14 @@ +import SocketServer + +class UDPHandler(SocketServer.BaseRequestHandler): + def handle(self): + data = self.request[0].strip() + socket = self.request[1] + print "{} wrote:".format(self.client_address[0]) + print data + socket.sendto(data.upper(), self.client_address) + +if __name__ == "__main__": + HOST, PORT = "localhost", 8019 + server = SocketServer.UDPServer((HOST, PORT), UDPHandler) + server.serve_forever() \ No newline at end of file From e2e31c1164f5a363ea6a6cbea5e59c7b558f4007 Mon Sep 17 00:00:00 2001 From: cib Date: Fri, 22 Jun 2012 01:09:21 -0700 Subject: [PATCH 03/15] Small improvements to DLLSocket --- DLLSocket/main.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/DLLSocket/main.cpp b/DLLSocket/main.cpp index d5b278593a5..07bb3d0b935 100644 --- a/DLLSocket/main.cpp +++ b/DLLSocket/main.cpp @@ -37,7 +37,7 @@ const char* SUCCESS = "1\0"; // string representing success // arg1: ip(in the xx.xx.xx.xx format) // arg2: port(a short) // return: NULL on failure, SUCCESS otherwise -extern "C" const char* establish_connection(int n, char *v[]) +extern "C" __declspec(dllexport) const char* establish_connection(int n, char *v[]) { // extract args // ------------ @@ -77,10 +77,11 @@ extern "C" const char* establish_connection(int n, char *v[]) // arg1: string message to send // return: NULL on failure, SUCCESS otherwise -extern "C" const char* send_message(int n, char *v[]) +extern "C" __declspec(dllexport) const char* send_message(int n, char *v[]) { // extract the args - const char* msg = v[1]; + if(n < 1) return 0; + const char* msg = v[0]; // send the message int rc = sendto(sock,msg,strlen(msg),0,(SOCKADDR*)&addr,sizeof(SOCKADDR)); @@ -96,7 +97,7 @@ extern "C" const char* send_message(int n, char *v[]) // no args // return: message if any received, NULL otherwise -extern "C" const char* recv_message(int n, char *v[]) +extern "C" __declspec(dllexport) const char* recv_message(int n, char *v[]) { SOCKADDR_IN sender; // we will store the sender address here From 610353c2a224cc37d0923310abe01163a1de825b Mon Sep 17 00:00:00 2001 From: cib Date: Fri, 22 Jun 2012 01:10:39 -0700 Subject: [PATCH 04/15] Started implementing the socket_talk API --- baystation12.dme | 3 +++ code/datums/configuration.dm | 4 ++++ code/game/cellautomata.dm | 1 + 3 files changed, 8 insertions(+) diff --git a/baystation12.dme b/baystation12.dme index 3cf3d6f5f7a..4341e938dcb 100644 --- a/baystation12.dme +++ b/baystation12.dme @@ -206,6 +206,7 @@ #define FILE_DIR "icons/vending_icons" #define FILE_DIR "interface" #define FILE_DIR "maps" +#define FILE_DIR "maps/backup" #define FILE_DIR "maps/RandomZLevels" #define FILE_DIR "sound" #define FILE_DIR "sound/AI" @@ -226,6 +227,7 @@ // END_PREFERENCES // BEGIN_INCLUDE #include "code\access_defines.dm" +#include "code\dlltest.dm" #include "code\names.dm" #include "code\setup.dm" #include "code\stylesheet.dm" @@ -379,6 +381,7 @@ #include "code\game\shuttle_engines.dm" #include "code\game\skincmd.dm" #include "code\game\smoothwall.dm" +#include "code\game\socket_talk.dm" #include "code\game\sound.dm" #include "code\game\specops_shuttle.dm" #include "code\game\status.dm" diff --git a/code/datums/configuration.dm b/code/datums/configuration.dm index f0cfee61dfc..67dec25042e 100644 --- a/code/datums/configuration.dm +++ b/code/datums/configuration.dm @@ -25,6 +25,7 @@ var/vote_period = 60 // length of voting period (seconds, default 1 minute) var/vote_no_default = 0 // vote does not default to nochange/norestart (tbi) var/vote_no_dead = 0 // dead people can't vote (tbi) + var/socket_talk = 0 // use socket_talk to communicate with other processes // var/enable_authentication = 0 // goon authentication var/del_new_on_log = 1 // del's new players if they log before they spawn in var/feature_object_spell_system = 0 //spawns a spellbook which gives object-type spells instead of verb-type spells for the wizard @@ -309,6 +310,9 @@ if("ticklag") Ticklag = text2num(value) + if("socket_talk") + socket_talk = text2num(value) + if("tickcomp") Tickcomp = 1 diff --git a/code/game/cellautomata.dm b/code/game/cellautomata.dm index 7034c022a2b..466eee1b3e3 100644 --- a/code/game/cellautomata.dm +++ b/code/game/cellautomata.dm @@ -137,6 +137,7 @@ src.update_status() + socket_talk = new /datum/socket_talk() master_controller = new /datum/controller/game_controller() spawn(-1) master_controller.setup() From 02e7f30a9eed0fd63dc677a32719f6ec5b475d52 Mon Sep 17 00:00:00 2001 From: cib Date: Fri, 22 Jun 2012 13:37:50 -0700 Subject: [PATCH 05/15] Refined the BYOND-side socket_talk interface --- code/game/master_controller.dm | 17 ++++++++++++++++- code/game/socket_talk.dm | 27 +++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 code/game/socket_talk.dm diff --git a/code/game/master_controller.dm b/code/game/master_controller.dm index 6f43d698129..e614099ee15 100644 --- a/code/game/master_controller.dm +++ b/code/game/master_controller.dm @@ -22,17 +22,27 @@ datum/controller/game_controller var/global/ticker_ready = 0 proc + keepalive() setup() setup_objects() process() set_debug_state(txt) + keepalive() + spawn while(1) + sleep(10) + + // Notify the other process that we're still there + socket_talk.send_keepalive() + setup() if(master_controller && (master_controller != src)) del(src) return //There can be only one master. + socket_talk = new /datum/socket_talk() + if(!air_master) air_master = new /datum/controller/air_system() air_master.setup() @@ -73,6 +83,8 @@ datum/controller/game_controller setupfactions() + spawn keepalive() + spawn ticker.pregame() @@ -109,7 +121,7 @@ datum/controller/game_controller // This should describe what is currently being done by the master controller // Useful for crashlogs and similar, because that way it's easy to tell what // was going on when the server crashed. - + socket_talk.send_log("crashlog.txt","TickerState: [txt]") return process() @@ -141,6 +153,9 @@ datum/controller/game_controller powernets_ready = 0 ticker_ready = 0 + // Notify the other process that we're still there + socket_talk.send_keepalive() + // the fact that the air master is not in the master controller // will make it very hard to find out whether it's responsible // for crashes diff --git a/code/game/socket_talk.dm b/code/game/socket_talk.dm new file mode 100644 index 00000000000..7b4568cdc6b --- /dev/null +++ b/code/game/socket_talk.dm @@ -0,0 +1,27 @@ +// Module used for fast interprocess communication between BYOND and other processes + +/datum/socket_talk + var + enabled = 0 + library_name = + New() + ..() + src.enabled = config.socket_talk + + if(enabled) + call("DLLSocket.so","establish_connection")("127.0.0.1","8019") + + proc + send_raw(message) + if(enabled) + return call("DLLSocket.so","send_message")(message) + receive_raw() + if(enabled) + return call("DLLSocket.so","recv_message")() + send_log(var/log, var/message) + return send_raw("type=log&log=[log]&message=[message]") + send_keepalive() + return send_raw("type=keepalive") + + +var/global/datum/socket_talk/socket_talk \ No newline at end of file From 5caee090826a11898b8aea3a8f169dc1e2dd6c9b Mon Sep 17 00:00:00 2001 From: cib Date: Fri, 22 Jun 2012 13:40:43 -0700 Subject: [PATCH 06/15] Linux compile-fix for DLLSocket/main.cpp --- DLLSocket/main.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/DLLSocket/main.cpp b/DLLSocket/main.cpp index 07bb3d0b935..42682be889f 100644 --- a/DLLSocket/main.cpp +++ b/DLLSocket/main.cpp @@ -11,6 +11,8 @@ #include #include #include + #include + #include } typedef int SOCKET; From 6caeb52b4c4db4b87796f45e8b6170a59c7eabc0 Mon Sep 17 00:00:00 2001 From: cib Date: Fri, 22 Jun 2012 13:40:43 -0700 Subject: [PATCH 07/15] Linux compile-fix for DLLSocket/main.cpp --- DLLSocket/main.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/DLLSocket/main.cpp b/DLLSocket/main.cpp index 07bb3d0b935..1e4d03e2fb7 100644 --- a/DLLSocket/main.cpp +++ b/DLLSocket/main.cpp @@ -11,6 +11,8 @@ #include #include #include + #include + #include } typedef int SOCKET; @@ -34,10 +36,16 @@ char return_buffer[BUFFER_SIZE]; const char* SUCCESS = "1\0"; // string representing success +#ifdef __WIN32 + #define DLL_EXPORT __declspec(dllexport) +#else + #define DLL_EXPORT _attribute__ ((visibility ("default"))) +#endif + // arg1: ip(in the xx.xx.xx.xx format) // arg2: port(a short) // return: NULL on failure, SUCCESS otherwise -extern "C" __declspec(dllexport) const char* establish_connection(int n, char *v[]) +extern "C" DLL_EXPORT const char* establish_connection(int n, char *v[]) { // extract args // ------------ @@ -77,7 +85,7 @@ extern "C" __declspec(dllexport) const char* establish_connection(int n, char *v // arg1: string message to send // return: NULL on failure, SUCCESS otherwise -extern "C" __declspec(dllexport) const char* send_message(int n, char *v[]) +extern "C" DLL_EXPORT const char* send_message(int n, char *v[]) { // extract the args if(n < 1) return 0; @@ -97,7 +105,7 @@ extern "C" __declspec(dllexport) const char* send_message(int n, char *v[]) // no args // return: message if any received, NULL otherwise -extern "C" __declspec(dllexport) const char* recv_message(int n, char *v[]) +extern "C" DLL_EXPORT const char* recv_message(int n, char *v[]) { SOCKADDR_IN sender; // we will store the sender address here From 5ea5af38d7c437a8f8a2a713265e323624c29760 Mon Sep 17 00:00:00 2001 From: cib Date: Sat, 23 Jun 2012 00:52:58 +0400 Subject: [PATCH 08/15] Another linux compile fix. --- DLLSocket/compile.sh | 1 + DLLSocket/main.cpp | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) create mode 100755 DLLSocket/compile.sh diff --git a/DLLSocket/compile.sh b/DLLSocket/compile.sh new file mode 100755 index 00000000000..0ff309bdb9f --- /dev/null +++ b/DLLSocket/compile.sh @@ -0,0 +1 @@ +g++ -static -shared -O3 -fPIC main.cpp -o DLLSocket.so diff --git a/DLLSocket/main.cpp b/DLLSocket/main.cpp index 1e4d03e2fb7..4516de19306 100644 --- a/DLLSocket/main.cpp +++ b/DLLSocket/main.cpp @@ -39,7 +39,7 @@ const char* SUCCESS = "1\0"; // string representing success #ifdef __WIN32 #define DLL_EXPORT __declspec(dllexport) #else - #define DLL_EXPORT _attribute__ ((visibility ("default"))) + #define DLL_EXPORT __attribute__ ((visibility ("default"))) #endif // arg1: ip(in the xx.xx.xx.xx format) From 4cfbf31ab5c392e805b2407b2d053cab536a863b Mon Sep 17 00:00:00 2001 From: cib Date: Fri, 22 Jun 2012 13:58:30 -0700 Subject: [PATCH 09/15] Rewrote server_controller.py functionality --- DLLSocket/server_controller.py | 43 ++++++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 12 deletions(-) diff --git a/DLLSocket/server_controller.py b/DLLSocket/server_controller.py index d1eb09cb02f..896c2a62013 100644 --- a/DLLSocket/server_controller.py +++ b/DLLSocket/server_controller.py @@ -1,14 +1,33 @@ -import SocketServer +import subprocess +import socket +import urlparse -class UDPHandler(SocketServer.BaseRequestHandler): - def handle(self): - data = self.request[0].strip() - socket = self.request[1] - print "{} wrote:".format(self.client_address[0]) - print data - socket.sendto(data.upper(), self.client_address) +UDP_IP="127.0.0.1" +UDP_PORT=8019 -if __name__ == "__main__": - HOST, PORT = "localhost", 8019 - server = SocketServer.UDPServer((HOST, PORT), UDPHandler) - server.serve_forever() \ No newline at end of file +sock = socket.socket( socket.AF_INET, # Internet + socket.SOCK_DGRAM ) # UDP +sock.bind( (UDP_IP,UDP_PORT) ) + +def handle_message(data, addr): + params = urlparse.parse_qs(data) + print(data) + + try: + if params["type"][0] == "log" and str(params["log"][0]) and str(params["message"][0]): + open(params["log"][0],"a+").write(params["message"][0]+"\n") + except IOError: + pass + except KeyError: + pass + +while True: + try: + data, addr = sock.recvfrom( 1024 ) # buffer size is 1024 bytes + handle_message(data,addr) + except socket.timeout: + print("No response in 120 seconds.. Trying to reboot server.") + subprocess.call("./restart") + + # start expecting a message after the first timeout + sock.settimeout(120) \ No newline at end of file From c859b1b021ae56f0089d222a61100eac8fc58331 Mon Sep 17 00:00:00 2001 From: cib Date: Sat, 23 Jun 2012 01:00:38 +0400 Subject: [PATCH 10/15] Fixed .dme derp --- baystation12.dme | 1 - 1 file changed, 1 deletion(-) diff --git a/baystation12.dme b/baystation12.dme index 4341e938dcb..af256c69d7f 100644 --- a/baystation12.dme +++ b/baystation12.dme @@ -227,7 +227,6 @@ // END_PREFERENCES // BEGIN_INCLUDE #include "code\access_defines.dm" -#include "code\dlltest.dm" #include "code\names.dm" #include "code\setup.dm" #include "code\stylesheet.dm" From 7b0b71dc4e9542a675725e0520d0d8fffc1a3f62 Mon Sep 17 00:00:00 2001 From: cib Date: Fri, 22 Jun 2012 14:11:18 -0700 Subject: [PATCH 11/15] Fixed a compile error. --- code/game/socket_talk.dm | 1 - 1 file changed, 1 deletion(-) diff --git a/code/game/socket_talk.dm b/code/game/socket_talk.dm index 7b4568cdc6b..b6024f3a191 100644 --- a/code/game/socket_talk.dm +++ b/code/game/socket_talk.dm @@ -3,7 +3,6 @@ /datum/socket_talk var enabled = 0 - library_name = New() ..() src.enabled = config.socket_talk From ae659b251e1f8e2f90dce60c7f95518d00f37900 Mon Sep 17 00:00:00 2001 From: cib Date: Fri, 22 Jun 2012 14:11:45 -0700 Subject: [PATCH 12/15] Added a socket_talk option to the config. --- config/config.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/config/config.txt b/config/config.txt index 5c47d1f156c..cfc5138a669 100644 --- a/config/config.txt +++ b/config/config.txt @@ -163,5 +163,8 @@ TICKLAG 0.9 ## Defines if Tick Compensation is used. It results in a minor slowdown of movement of all mobs, but attempts to result in a level movement speed across all ticks. Recommended if tickrate is lowered. TICKCOMP 0 +## Whether the server will talk to other processes through socket_talk +SOCKET_TALK 0 + ## Uncomment to restrict non-admins using humanoid alien races USEALIENWHITELIST From 55291ca8374b26c9d5a9bf9b805e7bed5b301a6f Mon Sep 17 00:00:00 2001 From: cib Date: Fri, 22 Jun 2012 14:42:48 -0700 Subject: [PATCH 13/15] Removed the automatic reboot stuff from server_controller.py --- DLLSocket/server_controller.py | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/DLLSocket/server_controller.py b/DLLSocket/server_controller.py index 896c2a62013..5c50da8a204 100644 --- a/DLLSocket/server_controller.py +++ b/DLLSocket/server_controller.py @@ -22,12 +22,5 @@ def handle_message(data, addr): pass while True: - try: - data, addr = sock.recvfrom( 1024 ) # buffer size is 1024 bytes - handle_message(data,addr) - except socket.timeout: - print("No response in 120 seconds.. Trying to reboot server.") - subprocess.call("./restart") - - # start expecting a message after the first timeout - sock.settimeout(120) \ No newline at end of file + data, addr = sock.recvfrom( 1024 ) # buffer size is 1024 bytes + handle_message(data,addr) \ No newline at end of file From 688e8e0ac0c9f6da944e5b448f25fca1c2d155df Mon Sep 17 00:00:00 2001 From: cib Date: Fri, 22 Jun 2012 15:22:48 -0700 Subject: [PATCH 14/15] Refined the socket_talk protocol for debugging purposes. --- DLLSocket/server_controller.py | 16 ++++++++++++++++ code/game/master_controller.dm | 5 ++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/DLLSocket/server_controller.py b/DLLSocket/server_controller.py index 5c50da8a204..19dd13f7533 100644 --- a/DLLSocket/server_controller.py +++ b/DLLSocket/server_controller.py @@ -9,6 +9,8 @@ sock = socket.socket( socket.AF_INET, # Internet socket.SOCK_DGRAM ) # UDP sock.bind( (UDP_IP,UDP_PORT) ) +last_ticker_state = None + def handle_message(data, addr): params = urlparse.parse_qs(data) print(data) @@ -20,6 +22,20 @@ def handle_message(data, addr): pass except KeyError: pass + + try: + if params["type"][0] == "ticker_state" and str(params["message"][0]): + last_ticker_state = str(params["message"][0]) + except KeyError: + pass + + try: + global last_ticker_state + if params["type"][0] == "startup" and last_ticker_state: + open("crashlog.txt","a+").write("Server exited, last ticker state was: "+last_ticker_state) + except KeyError: + pass + while True: data, addr = sock.recvfrom( 1024 ) # buffer size is 1024 bytes diff --git a/code/game/master_controller.dm b/code/game/master_controller.dm index e614099ee15..1fc6a160da1 100644 --- a/code/game/master_controller.dm +++ b/code/game/master_controller.dm @@ -43,6 +43,9 @@ datum/controller/game_controller socket_talk = new /datum/socket_talk() + // notify the other process that we started up + socket_talk.send_raw("type=startup") + if(!air_master) air_master = new /datum/controller/air_system() air_master.setup() @@ -121,7 +124,7 @@ datum/controller/game_controller // This should describe what is currently being done by the master controller // Useful for crashlogs and similar, because that way it's easy to tell what // was going on when the server crashed. - socket_talk.send_log("crashlog.txt","TickerState: [txt]") + socket_talk.send_raw("type=ticker_state&message=[txt]") return process() From 2a2f862de404197af07a9bf412d0f6026fd79f66 Mon Sep 17 00:00:00 2001 From: cib Date: Fri, 22 Jun 2012 16:42:54 -0700 Subject: [PATCH 15/15] Fixed a few minor errors in the server_controller script --- DLLSocket/server_controller.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/DLLSocket/server_controller.py b/DLLSocket/server_controller.py index 19dd13f7533..89303755cc9 100644 --- a/DLLSocket/server_controller.py +++ b/DLLSocket/server_controller.py @@ -12,6 +12,8 @@ sock.bind( (UDP_IP,UDP_PORT) ) last_ticker_state = None def handle_message(data, addr): + global last_ticker_state + params = urlparse.parse_qs(data) print(data) @@ -30,9 +32,8 @@ def handle_message(data, addr): pass try: - global last_ticker_state if params["type"][0] == "startup" and last_ticker_state: - open("crashlog.txt","a+").write("Server exited, last ticker state was: "+last_ticker_state) + open("crashlog.txt","a+").write("Server exited, last ticker state was: "+last_ticker_state+"\n") except KeyError: pass