tFixes to compile properly when networking is disabled - vaccinewars - be a doc… | |
git clone git://src.adamsgaard.dk/vaccinewars | |
Log | |
Files | |
Refs | |
README | |
LICENSE | |
--- | |
commit 19ae1233f9890b07e39fe9b5468a2e0a814967e7 | |
parent 5ea8f28c66b7d3ec785d0779ac9ce41f49754a79 | |
Author: Ben Webb <[email protected]> | |
Date: Sun, 17 Jun 2001 20:40:51 +0000 | |
Fixes to compile properly when networking is disabled | |
Diffstat: | |
M src/curses_client.c | 14 +++++++++++--- | |
M src/dopeos.h | 3 ++- | |
M src/dopewars.c | 15 ++++++++++++++- | |
M src/gtk_client.c | 69 ++++++++++++++++++++++-------… | |
M src/message.c | 4 ++++ | |
M src/message.h | 2 ++ | |
M src/serverside.c | 4 ++++ | |
7 files changed, 87 insertions(+), 24 deletions(-) | |
--- | |
diff --git a/src/curses_client.c b/src/curses_client.c | |
t@@ -44,7 +44,11 @@ static void PrintHighScore(char *Data); | |
static int ResizedFlag; | |
static SCREEN *cur_screen; | |
+ | |
+#ifdef NETWORKING | |
static char ConnectMethod=CM_SERVER; | |
+#endif | |
+ | |
static gboolean CanFire=FALSE,RunHere=FALSE; | |
static gchar FightPoint; | |
t@@ -1495,19 +1499,23 @@ static void Curses_DoGame(Player *Play) { | |
/* dopewars is essentially server-driven, so this loop simply has to */ | |
/* make the screen look pretty, respond to user keypresses, and react */ | |
/* to messages from the server. */ | |
- gchar *buf,*OldName,*TalkMsg,*pt; | |
+ gchar *buf,*OldName,*TalkMsg; | |
GString *text; | |
int i,c; | |
char IsCarrying; | |
#if NETWORKING || HAVE_SELECT | |
- fd_set readfs,writefs; | |
+ fd_set readfs; | |
+#endif | |
+#ifdef NETWORKING | |
+ fd_set writefs; | |
+ gboolean DoneOK; | |
+ gchar *pt; | |
#endif | |
int NumDrugsHere; | |
int MaxSock; | |
char HaveWorthless; | |
Player *tmp; | |
struct sigaction sact; | |
- gboolean DoneOK; | |
DisplayMode=DM_NONE; | |
QuitRequest=FALSE; | |
diff --git a/src/dopeos.h b/src/dopeos.h | |
t@@ -136,9 +136,10 @@ void SetReuse(SOCKET sock); | |
#include <arpa/inet.h> | |
#include <netdb.h> | |
#include <unistd.h> | |
-#include <errno.h> | |
#endif /* NETWORKING */ | |
+#include <errno.h> | |
+ | |
/* Only include sys/wait.h on those systems which support it */ | |
#if HAVE_SYS_WAIT_H | |
#include <sys/wait.h> | |
diff --git a/src/dopewars.c b/src/dopewars.c | |
t@@ -1751,6 +1751,7 @@ GString *GetLogString(GLogLevelFlags log_level,const gch… | |
#ifndef CYGWIN | |
+#ifdef NETWORKING | |
static void ServerLogMessage(const gchar *log_domain,GLogLevelFlags log_level, | |
const gchar *message,gpointer user_data) { | |
GString *text; | |
t@@ -1759,6 +1760,7 @@ static void ServerLogMessage(const gchar *log_domain,GLo… | |
g_print("%s\n",text->str); g_string_free(text,TRUE); | |
} | |
} | |
+#endif | |
/* Standard program entry - Win32 uses WinMain() instead, in winmain.c */ | |
int main(int argc,char *argv[]) { | |
t@@ -1771,8 +1773,11 @@ int main(int argc,char *argv[]) { | |
if (WantVersion || WantHelp) { | |
HandleHelpTexts(); | |
} else { | |
+#ifdef NETWORKING | |
StartNetworking(); | |
+#endif | |
if (Server) { | |
+#ifdef NETWORKING | |
#ifdef GUI_SERVER | |
gtk_set_locale(); | |
gtk_init(&argc,&argv); | |
t@@ -1781,7 +1786,13 @@ int main(int argc,char *argv[]) { | |
/* Deal with dopelog() stuff nicely */ | |
g_log_set_handler(NULL,LogMask(),ServerLogMessage,NULL); | |
ServerLoop(); | |
-#endif | |
+#endif /* GUI_SERVER */ | |
+#else | |
+ g_print(_("This binary has been compiled without networking " | |
+ "support, and thus cannot run\nin server mode. " | |
+ "Recompile passing --enable-networking to the " | |
+ "configure script.\n")); | |
+#endif /* NETWORKING */ | |
} else if (AIPlayer) { | |
AIPlayerLoop(); | |
} else switch(WantedClient) { | |
t@@ -1793,7 +1804,9 @@ int main(int argc,char *argv[]) { | |
case CLIENT_CURSES: | |
CursesLoop(); break; | |
} | |
+#ifdef NETWORKING | |
StopNetworking(); | |
+#endif | |
} | |
} | |
CloseHighScoreFile(); | |
diff --git a/src/gtk_client.c b/src/gtk_client.c | |
t@@ -72,7 +72,12 @@ struct ClientDataStruct { | |
}; | |
static struct ClientDataStruct ClientData; | |
-static gboolean InGame=FALSE,MetaServerRead=FALSE; | |
+static gboolean InGame=FALSE; | |
+ | |
+#ifdef NETWORKING | |
+static gboolean MetaServerRead=FALSE; | |
+#endif | |
+ | |
static GtkWidget *FightDialog=NULL,*SpyReportsDialog; | |
static gboolean IsShowingPlayerList=FALSE,IsShowingTalkList=FALSE, | |
IsShowingInventory=FALSE,IsShowingGunShop=FALSE; | |
t@@ -87,9 +92,13 @@ static void NewGameDialog(); | |
static void StartGame(); | |
static void EndGame(); | |
static void UpdateMenus(); | |
+ | |
+#ifdef NETWORKING | |
static void GetClientMessage(gpointer data,gint socket, | |
GdkInputCondition condition); | |
static void SetSocketWriteTest(Player *Play,gboolean WriteTest); | |
+#endif | |
+ | |
static void HandleClientMessage(char *buf,Player *Play); | |
static void PrepareHighScoreDialog(); | |
static void AddScoreToDialog(char *Data); | |
t@@ -254,6 +263,7 @@ void ListInventory(GtkWidget *widget,gpointer data) { | |
gtk_widget_show_all(window); | |
} | |
+#ifdef NETWORKING | |
void GetClientMessage(gpointer data,gint socket, | |
GdkInputCondition condition) { | |
gchar *pt; | |
t@@ -284,6 +294,7 @@ void SetSocketWriteTest(Player *Play,gboolean WriteTest) { | |
GetClientMessage,NULL); | |
} | |
} | |
+#endif /* NETWORKING */ | |
void HandleClientMessage(char *pt,Player *Play) { | |
char *Data,Code,AICode,DisplayMode; | |
t@@ -1508,16 +1519,18 @@ void StartGame() { | |
Player *Play; | |
Play=ClientData.Play=g_new(Player,1); | |
FirstClient=AddPlayer(0,Play,FirstClient); | |
+#ifdef NETWORKING | |
BindNetworkBufferToSocket(&Play->NetBuf,ClientSock); | |
+#endif | |
InitAbilities(Play); | |
SendAbilities(Play); | |
SetPlayerName(Play,ClientData.PlayerName); | |
SendNullClientMessage(Play,C_NONE,C_NAME,NULL,ClientData.PlayerName); | |
InGame=TRUE; | |
UpdateMenus(); | |
- if (Network) { | |
- SetSocketWriteTest(Play,TRUE); | |
- } | |
+#ifdef NETWORKING | |
+ if (Network) SetSocketWriteTest(Play,TRUE); | |
+#endif | |
gtk_widget_show_all(ClientData.vbox); | |
UpdatePlayerLists(); | |
} | |
t@@ -1699,7 +1712,9 @@ char GtkLoop(int *argc,char **argv[],char ReturnOnFail) { | |
/* Set up message handlers */ | |
ClientMessageHandlerPt = HandleClientMessage; | |
ClientData.GdkInputTag=0; | |
+#ifdef NETWORKING | |
SocketWriteTestPt = SetSocketWriteTest; | |
+#endif | |
/* Have the GLib log messages pop up in a nice dialog box */ | |
g_log_set_handler(NULL,LogMask()|G_LOG_LEVEL_MESSAGE | G_LOG_LEVEL_WARNING, | |
t@@ -1869,6 +1884,7 @@ struct StartGameStruct { | |
gint ConnectTag; | |
}; | |
+#ifdef NETWORKING | |
static void FinishServerConnect(gpointer data,gint socket, | |
GdkInputCondition condition) { | |
gchar *text,*NetworkError; | |
t@@ -1925,17 +1941,6 @@ static void ConnectToServer(GtkWidget *widget,struct St… | |
DoConnect(widgets); | |
} | |
-static void StartSinglePlayer(GtkWidget *widget, | |
- struct StartGameStruct *widgets) { | |
- WantAntique= | |
- gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->antique)); | |
- g_free(ClientData.PlayerName); | |
- ClientData.PlayerName=gtk_editable_get_chars(GTK_EDITABLE(widgets->name), | |
- 0,-1); | |
- StartGame(); | |
- gtk_widget_destroy(widgets->dialog); | |
-} | |
- | |
static void FillMetaServerList(struct StartGameStruct *widgets) { | |
GtkWidget *metaserv; | |
ServerData *ThisServer; | |
t@@ -2007,23 +2012,39 @@ static void MetaServerConnect(GtkWidget *widget, | |
DoConnect(widgets); | |
} | |
} | |
+#endif /* NETWORKING */ | |
+ | |
+static void StartSinglePlayer(GtkWidget *widget, | |
+ struct StartGameStruct *widgets) { | |
+ WantAntique= | |
+ gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->antique)); | |
+ g_free(ClientData.PlayerName); | |
+ ClientData.PlayerName=gtk_editable_get_chars(GTK_EDITABLE(widgets->name), | |
+ 0,-1); | |
+ StartGame(); | |
+ gtk_widget_destroy(widgets->dialog); | |
+} | |
static void CloseNewGameDia(GtkWidget *widget, | |
struct StartGameStruct *widgets) { | |
+#ifdef NETWORKING | |
if (widgets->ConnectTag!=0) { | |
- gdk_input_remove(widgets->ConnectTag); CloseSocket(ClientSock); | |
+ gdk_input_remove(widgets->ConnectTag); | |
+ CloseSocket(ClientSock); | |
widgets->ConnectTag=0; | |
} | |
+#endif | |
} | |
void NewGameDialog() { | |
GtkWidget *vbox,*vbox2,*hbox,*label,*entry,*notebook,*frame,*button; | |
- GtkWidget *table,*clist,*scrollwin,*dialog,*hbbox; | |
+ GtkWidget *dialog; | |
GtkAccelGroup *accel_group; | |
- gchar *text; | |
- gchar *server_titles[5],*ServerEntry; | |
static struct StartGameStruct widgets; | |
guint AccelKey; | |
+#ifdef NETWORKING | |
+ GtkWidget *clist,*scrollwin,*table,*hbbox; | |
+ gchar *server_titles[5],*ServerEntry,*text; | |
gboolean UpdateMeta=FALSE; | |
/* Column titles of metaserver information */ | |
t@@ -2032,6 +2053,7 @@ void NewGameDialog() { | |
server_titles[2]=_("Version"); | |
server_titles[3]=_("Players"); | |
server_titles[4]=_("Comment"); | |
+#endif /* NETWORKING */ | |
widgets.ConnectTag=0; | |
widgets.dialog=dialog=gtk_window_new(GTK_WINDOW_DIALOG); | |
t@@ -2042,7 +2064,9 @@ void NewGameDialog() { | |
gtk_window_set_modal(GTK_WINDOW(dialog),TRUE); | |
gtk_window_set_transient_for(GTK_WINDOW(dialog), | |
GTK_WINDOW(ClientData.window)); | |
+#ifdef NETWORKING | |
gtk_window_set_default_size(GTK_WINDOW(dialog),500,300); | |
+#endif | |
accel_group=gtk_accel_group_new(); | |
/* Title of 'New Game' dialog */ | |
t@@ -2072,6 +2096,7 @@ void NewGameDialog() { | |
notebook=gtk_notebook_new(); | |
+#ifdef NETWORKING | |
frame=gtk_frame_new(_("Server")); | |
gtk_container_set_border_width(GTK_CONTAINER(frame),4); | |
vbox2=gtk_vbox_new(FALSE,7); | |
t@@ -2125,6 +2150,7 @@ void NewGameDialog() { | |
label=gtk_label_new(_("Server")); | |
gtk_notebook_append_page(GTK_NOTEBOOK(notebook),frame,label); | |
+#endif /* NETWORKING */ | |
/* Title of 'New Game' dialog notebook tab for single-player mode */ | |
frame=gtk_frame_new(_("Single player")); | |
t@@ -2152,6 +2178,7 @@ void NewGameDialog() { | |
label=gtk_label_new(_("Single player")); | |
gtk_notebook_append_page(GTK_NOTEBOOK(notebook),frame,label); | |
+#ifdef NETWORKING | |
/* Title of Metaserver frame in New Game dialog */ | |
frame=gtk_frame_new(_("Metaserver")); | |
gtk_container_set_border_width(GTK_CONTAINER(frame),4); | |
t@@ -2192,6 +2219,8 @@ void NewGameDialog() { | |
label=gtk_label_new(_("Metaserver")); | |
gtk_notebook_append_page(GTK_NOTEBOOK(notebook),frame,label); | |
+#endif /* NETWORKING */ | |
+ | |
gtk_box_pack_start(GTK_BOX(vbox),notebook,TRUE,TRUE,0); | |
/* Caption of status label in New Game dialog before anything has happened */ | |
t@@ -2201,11 +2230,13 @@ void NewGameDialog() { | |
gtk_container_add(GTK_CONTAINER(widgets.dialog),vbox); | |
gtk_widget_grab_focus(widgets.name); | |
+#ifdef NETWORKING | |
if (UpdateMeta) { | |
UpdateMetaServerList(NULL,&widgets); | |
} else { | |
FillMetaServerList(&widgets); | |
} | |
+#endif | |
gtk_widget_show_all(widgets.dialog); | |
gtk_notebook_set_page(GTK_NOTEBOOK(notebook),NewGameType); | |
diff --git a/src/message.c b/src/message.c | |
t@@ -1004,7 +1004,9 @@ void SwitchToSinglePlayer(Player *Play) { | |
FirstClient=RemovePlayer((Player *)g_slist_next(FirstClient)->data, | |
FirstClient); | |
} | |
+#ifdef NETWORKING | |
CloseSocket(ClientSock); | |
+#endif | |
CleanUpServer(); | |
Network=Server=Client=FALSE; | |
InitAbilities(Play); | |
t@@ -1135,6 +1137,7 @@ gboolean HandleGenericClientMessage(Player *From,char AI… | |
return TRUE; | |
} | |
+#ifdef NETWORKING | |
char *OpenMetaServerConnection(int *HttpSock) { | |
static char NoHost[] = N_("Cannot locate metaserver"); | |
static char NoSocket[] = N_("Cannot create socket"); | |
t@@ -1218,6 +1221,7 @@ void ReadMetaServerData(int HttpSock) { | |
} | |
} | |
} | |
+#endif /* NETWORKING */ | |
void SendFightReload(Player *To) { | |
SendFightMessage(To,NULL,0,F_RELOAD,FALSE,FALSE,NULL); | |
diff --git a/src/message.h b/src/message.h | |
t@@ -177,10 +177,12 @@ int ProcessMessage(char *Msg,Player *Play,Player **Other… | |
void ReceiveDrugsHere(char *text,Player *To); | |
gboolean HandleGenericClientMessage(Player *From,char AICode,char Code, | |
Player *To,char *Data,char *DisplayMode); | |
+#ifdef NETWORKING | |
char *OpenMetaServerConnection(int *HttpSock); | |
void CloseMetaServerConnection(int HttpSock); | |
void ClearServerList(); | |
void ReadMetaServerData(int HttpSock); | |
+#endif | |
void InitAbilities(Player *Play); | |
void SendAbilities(Player *Play); | |
void ReceiveAbilities(Player *Play,gchar *Data); | |
diff --git a/src/serverside.c b/src/serverside.c | |
t@@ -76,7 +76,9 @@ gboolean MetaPlayerPending=FALSE; | |
GSList *FirstServer=NULL; | |
+#ifdef NETWORKING | |
static GScanner *Scanner; | |
+#endif | |
/* Data waiting to be sent to/read from the metaserver */ | |
NetworkBuffer MetaNetBuf; | |
t@@ -205,6 +207,7 @@ void RegisterWithMetaServer(gboolean Up,gboolean SendData, | |
#endif /* NETWORKING */ | |
} | |
+#ifdef NETWORKING | |
void HandleServerPlayer(Player *Play) { | |
gchar *buf; | |
gboolean MessageRead=FALSE; | |
t@@ -218,6 +221,7 @@ void HandleServerPlayer(Player *Play) { | |
Play->IdleTimeout=time(NULL)+(time_t)IdleTimeout; | |
} | |
} | |
+#endif /* NETWORKING */ | |
void SendPlayerDetails(Player *Play,Player *To,char Code) { | |
/* Sends details (name, ID) about player "Play" to player "To", using */ |