tBasic support for converting network messages to and from UTF-8. - vaccinewars… | |
git clone git://src.adamsgaard.dk/vaccinewars | |
Log | |
Files | |
Refs | |
README | |
LICENSE | |
--- | |
commit 144a831286a6d11ed7e534b991e412ad8bed983f | |
parent 203e30e33f384b52c4b4d60050b9722c6d876d90 | |
Author: Ben Webb <[email protected]> | |
Date: Mon, 5 Aug 2002 11:36:35 +0000 | |
Basic support for converting network messages to and from UTF-8. | |
Diffstat: | |
M src/dopewars.c | 4 +--- | |
M src/message.c | 39 +++++++++++++++++++++++++++++… | |
M src/message.h | 1 + | |
M src/winmain.c | 6 ++---- | |
4 files changed, 41 insertions(+), 9 deletions(-) | |
--- | |
diff --git a/src/dopewars.c b/src/dopewars.c | |
t@@ -2750,9 +2750,7 @@ int main(int argc, char *argv[]) | |
} else if (WantConvert) { | |
ConvertHighScoreFile(); | |
} else { | |
-#ifdef NETWORKING | |
- StartNetworking(); | |
-#endif | |
+ InitNetwork(); | |
if (Server) { | |
#ifdef NETWORKING | |
#ifdef GUI_SERVER | |
diff --git a/src/message.c b/src/message.c | |
t@@ -36,6 +36,8 @@ | |
#include <string.h> | |
#include <stdlib.h> | |
#include <glib.h> | |
+ | |
+#include "convert.h" | |
#include "dopewars.h" | |
#include "message.h" | |
#include "network.h" | |
t@@ -100,6 +102,8 @@ | |
GSList *FirstClient; | |
+static Converter *netconv = NULL; | |
+ | |
void (*ClientMessageHandlerPt)(char *, Player *) = NULL; | |
/* | |
t@@ -247,7 +251,11 @@ void InitAbilities(Player *Play) | |
Play->Abil.Local[A_DRUGVALUE] = (DrugValue ? TRUE : FALSE); | |
Play->Abil.Local[A_TSTRING] = TRUE; | |
Play->Abil.Local[A_DONEFIGHT] = TRUE; | |
+#ifdef HAVE_GLIB2 | |
+ Play->Abil.Local[A_UTF8] = TRUE; | |
+#else | |
Play->Abil.Local[A_UTF8] = FALSE; | |
+#endif | |
if (!Network) { | |
for (i = 0; i < A_NUM; i++) { | |
t@@ -310,6 +318,10 @@ void CombineAbilities(Player *Play) | |
for (i = 0; i < A_NUM; i++) { | |
Play->Abil.Shared[i] = (Play->Abil.Remote[i] && Play->Abil.Local[i]); | |
} | |
+ | |
+ if (HaveAbility(Play, A_UTF8)) { | |
+ Conv_SetCodeset(netconv, "UTF-8"); | |
+ } | |
} | |
/* | |
t@@ -362,7 +374,16 @@ gboolean PlayerHandleNetwork(Player *Play, gboolean ReadR… | |
gchar *GetWaitingPlayerMessage(Player *Play) | |
{ | |
- return GetWaitingMessage(&Play->NetBuf); | |
+ gchar *unconv, *conv; | |
+ | |
+ unconv = GetWaitingMessage(&Play->NetBuf); | |
+ if (unconv && Conv_Needed(netconv)) { | |
+ conv = Conv_ToInternal(netconv, unconv, -1); | |
+ g_free(unconv); | |
+ return conv; | |
+ } else { | |
+ return unconv; | |
+ } | |
} | |
gboolean ReadPlayerDataFromWire(Player *Play) | |
t@@ -372,7 +393,13 @@ gboolean ReadPlayerDataFromWire(Player *Play) | |
void QueuePlayerMessageForSend(Player *Play, gchar *data) | |
{ | |
- QueueMessageForSend(&Play->NetBuf, data); | |
+ if (Conv_Needed(netconv)) { | |
+ gchar *conv = Conv_ToExternal(netconv, data, -1); | |
+ QueueMessageForSend(&Play->NetBuf, conv); | |
+ g_free(conv); | |
+ } else { | |
+ QueueMessageForSend(&Play->NetBuf, data); | |
+ } | |
} | |
gboolean WritePlayerDataToWire(Player *Play) | |
t@@ -935,6 +962,14 @@ void SwitchToSinglePlayer(Player *Play) | |
} | |
} | |
+void InitNetwork(void) | |
+{ | |
+ netconv = Conv_New(); | |
+#ifdef NETWORKING | |
+ StartNetworking(); | |
+#endif | |
+} | |
+ | |
/* | |
* Closes down the client side of the network connection. Clears the list | |
* of client players (with the exception of "you", the player "Play"), | |
diff --git a/src/message.h b/src/message.h | |
t@@ -93,6 +93,7 @@ extern GSList *FirstClient; | |
extern void (*ClientMessageHandlerPt) (char *, Player *); | |
+void InitNetwork(void); | |
void AddURLEnc(GString *str, gchar *unenc); | |
void chomp(char *str); | |
void BroadcastToClients(AICode AI, MsgCode Code, char *Data, Player *From, | |
diff --git a/src/winmain.c b/src/winmain.c | |
t@@ -280,7 +280,7 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevI… | |
WindowPrintEnd(); | |
#ifdef NETWORKING | |
} else if (is_service) { | |
- StartNetworking(); | |
+ InitNetwork(); | |
Network = Server = TRUE; | |
win32_init(hInstance, hPrevInstance, "mainicon"); | |
ServiceMain(); | |
t@@ -292,9 +292,7 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevI… | |
ConvertHighScoreFile(); | |
WindowPrintEnd(); | |
} else { | |
-#ifdef NETWORKING | |
- StartNetworking(); | |
-#endif | |
+ InitNetwork(); | |
if (Server) { | |
#ifdef NETWORKING | |
#ifdef GUI_SERVER |