tMessage or field terminators (i.e. \n or ^) are now stripped from player names, to avoid breaking the protocol. - 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 8c3a199c9f24b70a92eb4ca83b5499d25840d45e
(DIR) parent f0717f841153c6092b87320068b4adcb8d4b64dc
(HTM) Author: Ben Webb <ben@salilab.org>
Date: Mon, 29 Apr 2002 10:28:50 +0000
Message or field terminators (i.e. \n or ^) are now stripped from player
names, to avoid breaking the protocol.
Diffstat:
M src/curses_client/curses_client.c | 2 ++
M src/dopewars.c | 11 +++++++++--
M src/dopewars.h | 1 +
M src/gui_client/gtk_client.c | 2 ++
M src/serverside.c | 1 +
5 files changed, 15 insertions(+), 2 deletions(-)
---
(DIR) diff --git a/src/curses_client/curses_client.c b/src/curses_client/curses_client.c
t@@ -918,6 +918,7 @@ static void change_name(Player *Play, gboolean nullname)
NewName = nice_input(_("New name: "), 23, 0, FALSE, NULL, '\0');
if (NewName[0]) {
+ StripTerminators(NewName);
if (nullname) {
SendNullClientMessage(Play, C_NONE, C_NAME, NULL, NewName);
} else {
t@@ -2073,6 +2074,7 @@ static void Curses_DoGame(Player *Play)
InitAbilities(Play);
SendAbilities(Play);
+ StripTerminators(buf);
SetPlayerName(Play, buf);
SendNullClientMessage(Play, C_NONE, C_NAME, NULL, buf);
g_free(buf);
(DIR) diff --git a/src/dopewars.c b/src/dopewars.c
t@@ -2680,7 +2680,8 @@ void GeneralStartup(int argc, char *argv[])
}
/*
- * Removes any ^ characters from the given string, which is modified in place.
+ * Removes any ^ or \n characters from the given string, which is
+ * modified in place.
*/
void StripTerminators(gchar *str)
{
t@@ -2688,8 +2689,13 @@ void StripTerminators(gchar *str)
if (str) {
for (i = 0; i < strlen(str); i++) {
- if (str[i] == '^') {
+ switch(str[i]) {
+ case '^':
+ case '\n':
str[i] = '~';
+ break;
+ default:
+ break;
}
}
}
t@@ -2811,6 +2817,7 @@ int main(int argc, char *argv[])
bindtextdomain(PACKAGE, LOCALEDIR);
textdomain(PACKAGE);
#endif
+ WantUTF8Errors(FALSE);
GeneralStartup(argc, argv);
OpenLog();
if (WantVersion || WantHelp) {
(DIR) diff --git a/src/dopewars.h b/src/dopewars.h
t@@ -402,6 +402,7 @@ void HandleCmdLine(int argc, char *argv[]);
void SetupParameters(void);
void HandleHelpTexts(void);
void GeneralStartup(int argc, char *argv[]);
+void StripTerminators(gchar *str);
void ReadConfigFile(char *FileName);
gboolean ParseNextConfig(GScanner *scanner, gboolean print);
int GetGlobalIndex(gchar *ID1, gchar *ID2);
(DIR) diff --git a/src/gui_client/gtk_client.c b/src/gui_client/gtk_client.c
t@@ -1906,6 +1906,7 @@ void GuiStartGame(void)
InitAbilities(Play);
SendAbilities(Play);
+ StripTerminators(GetPlayerName(Play));
SendNullClientMessage(Play, C_NONE, C_NAME, NULL, GetPlayerName(Play));
InGame = TRUE;
UpdateMenus();
t@@ -3022,6 +3023,7 @@ static void NewNameOK(GtkWidget *widget, GtkWidget *window)
entry = GTK_WIDGET(gtk_object_get_data(GTK_OBJECT(window), "entry"));
text = gtk_editable_get_chars(GTK_EDITABLE(entry), 0, -1);
if (text[0]) {
+ StripTerminators(text);
SetPlayerName(ClientData.Play, text);
SendNullClientMessage(ClientData.Play, C_NONE, C_NAME, NULL, text);
gtk_widget_destroy(window);
(DIR) diff --git a/src/serverside.c b/src/serverside.c
t@@ -380,6 +380,7 @@ void HandleServerMessage(gchar *buf, Player *Play)
ReceiveAbilities(Play, Data);
break;
case C_NAME:
+ StripTerminators(Data);
pt = GetPlayerByName(Data, FirstServer);
if (pt && pt != Play) {
if (ConnectTimeout) {