tData sent to metaserver is now properly URL-encoded - vaccinewars - be a doctor and try to vaccinate the world (HTM) git clone git://src.adamsgaard.dk/vaccinewars (DIR) Log (DIR) Files (DIR) Refs (DIR) README (DIR) LICENSE --- (DIR) commit f94eee147bb0aae14b9b07cd5d068acc5c98801b (DIR) parent 1a70d1d77487fc5ef5e79af9b070b108aa4caa86 (HTM) Author: Ben Webb <ben@salilab.org> Date: Sun, 17 Jun 2001 19:38:17 +0000 Data sent to metaserver is now properly URL-encoded Diffstat: M README | 12 ++++++------ M src/message.c | 21 +++++++++++++++++++++ M src/message.h | 1 + M src/serverside.c | 21 ++++++++++++--------- 4 files changed, 40 insertions(+), 15 deletions(-) --- (DIR) diff --git a/README b/README t@@ -1,13 +1,13 @@ -This is dopewars 1.5.0, a game simulating the life of a drug dealer in +This is dopewars 1.5.1, a game simulating the life of a drug dealer in New York. The aim of the game is to make lots and lots of money... unfortunately, you start the game with a hefty debt, accumulating interest, and the cops take a rather dim view of drug dealing... These are brief instructions; see the HTML documentation for full information. -dopewars 1.5.0 servers should handle clients as old as version 1.4.3 with +dopewars 1.5.1 servers should handle clients as old as version 1.4.3 with hardly any visible problems (the reverse is also true). However, it is -recommended that both clients and servers are upgraded to 1.5.0! +recommended that both clients and servers are upgraded to 1.5.1! INSTALLATION t@@ -17,10 +17,10 @@ Either... Or... -2. Get the tarball dopewars-1.5.0.tar.gz from the same URL - Extract it via. tar -xvzf dopewars-1.5.0.tar.gz +2. Get the tarball dopewars-1.5.1.tar.gz from the same URL + Extract it via. tar -xvzf dopewars-1.5.1.tar.gz Follow the instructions in the INSTALL file in the newly-created - dopewars-1.5.0 directory + dopewars-1.5.1 directory Once you're done, you can safely delete the RPM, tarball and dopewars directory. The dopewars binary is all you need! (DIR) diff --git a/src/message.c b/src/message.c t@@ -600,6 +600,27 @@ void chomp(char *str) { if (str[len-1]=='\n') str[len-1]=0; } +void AddURLEnc(GString *str,gchar *unenc) { +/* Adds the plain text string "unenc" to the end of the GString "str", */ +/* replacing "special" characters in the same way as the */ +/* application/x-www-form-urlencoded media type, suitable for sending */ +/* to CGI scripts etc. */ + int i; + if (!unenc || !str) return; + for (i=0;i<strlen(unenc);i++) { + if ((unenc[i]>='a' && unenc[i]<='z') || + (unenc[i]>='A' && unenc[i]<='Z') || + (unenc[i]>='0' && unenc[i]<='9') || + unenc[i]=='-' || unenc[i]=='_' || unenc[i]=='.') { + g_string_append_c(str,unenc[i]); + } else if (unenc[i]==' ') { + g_string_append_c(str,'+'); + } else { + g_string_sprintfa(str,"%%%02X",unenc[i]); + } + } +} + void BroadcastToClients(char AICode,char Code,char *Data, Player *From,Player *Except) { /* Sends the message made up of AICode,Code and Data to all players except */ (DIR) diff --git a/src/message.h b/src/message.h t@@ -150,6 +150,7 @@ extern GSList *FirstClient; extern void (*ClientMessageHandlerPt) (char *,Player *); extern void (*SocketWriteTestPt) (Player *,gboolean); +void AddURLEnc(GString *str,gchar *unenc); void chomp(char *str); void BroadcastToClients(char AICode,char Code,char *Data,Player *From, Player *Except); (DIR) diff --git a/src/serverside.c b/src/serverside.c t@@ -177,19 +177,22 @@ void RegisterWithMetaServer(gboolean Up,gboolean SendData, g_string_assign(query,"output=text&"); - g_string_sprintfa(query,"up=%d&port=%d&version=%s&players=%d" - "&maxplay=%d&comment=%s", - Up ? 1 : 0,Port,VERSION,CountPlayers(FirstServer), - MaxClients,MetaServer.Comment); - + g_string_sprintfa(query,"up=%d&port=%d&version=",Up ? 1 : 0,Port); + AddURLEnc(query,VERSION); + g_string_sprintfa(query,"&players=%d&maxplay=%d&comment=", + CountPlayers(FirstServer),MaxClients); + AddURLEnc(query,MetaServer.Comment); if (SendData && HighScoreRead(MultiScore,AntiqueScore)) { for (i=0;i<NUMHISCORE;i++) { if (MultiScore[i].Name && MultiScore[i].Name[0]) { - g_string_sprintfa(query,"&nm[%d]=%s&dt[%d]=%s&st[%d]=%s&sc[%d]=%s", - i,MultiScore[i].Name,i,MultiScore[i].Time, - i,MultiScore[i].Dead ? "dead" : "alive", - i,prstr=FormatPrice(MultiScore[i].Money)); + g_string_sprintfa(query,"&nm[%d]=",i); + AddURLEnc(query,MultiScore[i].Name); + g_string_sprintfa(query,"&dt[%d]=",i); + AddURLEnc(query,MultiScore[i].Time); + g_string_sprintfa(query,"&st[%d]=%s&sc[%d]=",i, + MultiScore[i].Dead ? "dead" : "alive",i); + AddURLEnc(query,prstr=FormatPrice(MultiScore[i].Money)); g_free(prstr); } }