tOld metaserver communication code removed - vaccinewars - be a doctor and try … | |
git clone git://src.adamsgaard.dk/vaccinewars | |
Log | |
Files | |
Refs | |
README | |
LICENSE | |
--- | |
commit deb1942deb69bf7fbce7a15bb2ce2555155e5a2c | |
parent abf3aef9702f6f15adeeb0280e7ba60bad43acd8 | |
Author: Ben Webb <[email protected]> | |
Date: Wed, 12 Sep 2001 19:13:55 +0000 | |
Old metaserver communication code removed | |
Diffstat: | |
M src/curses_client.c | 39 ++++++++++++++++++++++++-----… | |
M src/message.c | 124 ++---------------------------… | |
M src/message.h | 9 +-------- | |
3 files changed, 39 insertions(+), 133 deletions(-) | |
--- | |
diff --git a/src/curses_client.c b/src/curses_client.c | |
t@@ -220,12 +220,15 @@ static char *SelectServerFromMetaServer(void) { | |
/* server/port pairs, one of which the user should select. */ | |
/* Returns a pointer to a static string containing an error */ | |
/* message if the connection failed, otherwise NULL. */ | |
- char *MetaError; | |
- int HttpSock,c; | |
+ int c; | |
GSList *ListPt; | |
ServerData *ThisServer; | |
GString *text; | |
gint index; | |
+ fd_set readfds,writefds; | |
+ int maxsock; | |
+ gboolean DoneOK=TRUE; | |
+ HttpConnection *MetaConn; | |
static char NoServers[] = N_("No servers listed on metaserver"); | |
attrset(TextAttr); | |
t@@ -233,16 +236,34 @@ static char *SelectServerFromMetaServer(void) { | |
mvaddstr(17,1,_("Please wait... attempting to contact metaserver...")); | |
refresh(); | |
- MetaError=OpenMetaServerConnection(&HttpSock); | |
- if (MetaError) return MetaError; | |
+ MetaConn = OpenMetaHttpConnection(); | |
- clear_line(17); | |
+ if (!MetaConn) return "Cannot connect"; | |
+ | |
+ ClearServerList(); | |
+ | |
+ while(DoneOK) { | |
+ FD_ZERO(&readfds); FD_ZERO(&writefds); | |
+ FD_SET(0,&readfds); maxsock=1; | |
+ SetSelectForNetworkBuffer(&MetaConn->NetBuf,&readfds,&writefds, | |
+ NULL,&maxsock); | |
+ if (bselect(maxsock,&readfds,&writefds,NULL,NULL)==-1) { | |
+ if (errno==EINTR) { /*CheckForResize(Play);*/ continue; } | |
+ perror("bselect"); exit(1); | |
+ } | |
+ if (RespondToSelect(&MetaConn->NetBuf,&readfds,&writefds,NULL,&DoneOK)) { | |
+ while (HandleWaitingMetaServerData(MetaConn)) {} | |
+ } | |
+ if (!DoneOK) { | |
+ g_print("Metaserver communication closed"); | |
+ } | |
+ } | |
+ CloseHttpConnection(MetaConn); | |
+ | |
+/* clear_line(17); | |
mvaddstr(17,1, | |
_("Connection to metaserver established. Obtaining server list...")); | |
- refresh(); | |
- | |
- ReadMetaServerData(HttpSock); | |
- CloseMetaServerConnection(HttpSock); | |
+ refresh();*/ | |
text=g_string_new(""); | |
diff --git a/src/message.c b/src/message.c | |
t@@ -774,36 +774,14 @@ gboolean HandleWaitingMetaServerData(HttpConnection *con… | |
return TRUE; | |
} | |
-gchar *bgets(int fd) { | |
-/* Drop-in substitute for fgets; reads a newline-terminated string from */ | |
-/* file descriptor fd, into a dynamically-allocated buffer. Returns a */ | |
-/* pointer to the buffer, or NULL if an error occurred. It is the user's */ | |
-/* responsibility to g_free the pointer when it is no longer needed. */ | |
-/* Used for non-blocking read from TCP sockets. */ | |
-/* N.B. The terminating newline is _not_ returned in the string. */ | |
- ssize_t len; | |
- unsigned TotalLen=0; | |
- GString *text; | |
- gchar *buffer; | |
- char tmp[10]; | |
- text=g_string_new(NULL); | |
- for (;;) { | |
- len=recv(fd,tmp,1,0); | |
- if (len==SOCKET_ERROR) { g_string_free(text,TRUE); return NULL; } | |
- if (len==0) { g_string_free(text,TRUE); return NULL; } | |
- if (tmp[0]=='\n') { | |
- buffer=text->str; | |
- g_string_free(text,FALSE); /* Just free the g_string, not the data */ | |
- return buffer; | |
- } else { | |
- g_string_append_c(text,tmp[0]); | |
- TotalLen++; | |
- /* Test to make sure dodgy clients don't eat all of our nice memory */ | |
- if (TotalLen > 64000) { | |
- g_warning("Abnormally large packet"); | |
- g_string_free(text,TRUE); return NULL; | |
- } | |
- } | |
+void ClearServerList() { | |
+ ServerData *ThisServer; | |
+ while (ServerList) { | |
+ ThisServer=(ServerData *)(ServerList->data); | |
+ g_free(ThisServer->Name); g_free(ThisServer->Comment); | |
+ g_free(ThisServer->Version); g_free(ThisServer->Update); | |
+ g_free(ThisServer->UpSince); g_free(ThisServer); | |
+ ServerList=g_slist_remove(ServerList,ThisServer); | |
} | |
} | |
#endif /* NETWORKING */ | |
t@@ -1355,92 +1333,6 @@ gboolean HandleGenericClientMessage(Player *From,AICode… | |
return TRUE; | |
} | |
-#ifdef NETWORKING | |
-char *OpenMetaServerConnection(int *HttpSock) { | |
- static char NoHost[] = N_("Cannot locate metaserver"); | |
- static char NoSocket[] = N_("Cannot create socket"); | |
- static char NoService[] = | |
- N_("Metaserver not running HTTP or connection denied"); | |
- struct sockaddr_in HttpAddr; | |
- struct hostent *he; | |
- gchar *MetaName; | |
- int MetaPort; | |
- | |
-/* If a proxy is defined, connect to that. Otherwise, connect to the | |
- metaserver directly */ | |
- if (MetaServer.ProxyName[0]) { | |
- MetaName=MetaServer.ProxyName; MetaPort=MetaServer.ProxyPort; | |
- } else { | |
- MetaName=MetaServer.Name; MetaPort=MetaServer.Port; | |
- } | |
- | |
- if ((he=gethostbyname(MetaName))==NULL) return NoHost; | |
- if ((*HttpSock=socket(AF_INET,SOCK_STREAM,0))==-1) return NoSocket; | |
- HttpAddr.sin_family=AF_INET; | |
- HttpAddr.sin_port=htons(MetaPort); | |
- HttpAddr.sin_addr=*((struct in_addr *)he->h_addr); | |
- memset(HttpAddr.sin_zero,0,sizeof(HttpAddr.sin_zero)); | |
- if (connect(*HttpSock,(struct sockaddr *)&HttpAddr, | |
- sizeof(struct sockaddr))==SOCKET_ERROR) { | |
- CloseSocket(*HttpSock); | |
- return NoService; | |
- } | |
- return NULL; | |
-} | |
- | |
-void CloseMetaServerConnection(int HttpSock) { | |
- CloseSocket(HttpSock); | |
-} | |
- | |
-void ClearServerList() { | |
- ServerData *ThisServer; | |
- while (ServerList) { | |
- ThisServer=(ServerData *)(ServerList->data); | |
- g_free(ThisServer->Name); g_free(ThisServer->Comment); | |
- g_free(ThisServer->Version); g_free(ThisServer->Update); | |
- g_free(ThisServer->UpSince); g_free(ThisServer); | |
- ServerList=g_slist_remove(ServerList,ThisServer); | |
- } | |
-} | |
- | |
-void ReadMetaServerData(int HttpSock) { | |
- gchar *buf; | |
- ServerData *NewServer; | |
- gboolean HeaderDone; | |
- | |
- ClearServerList(); | |
- buf=g_strdup_printf("GET %s?output=text&getlist=%d HTTP/1.1\n" | |
- "Host: %s:%d\n\n",MetaServer.Path,METAVERSION, | |
- MetaServer.Name,MetaServer.Port); | |
- send(HttpSock,buf,strlen(buf),0); | |
- g_free(buf); | |
- HeaderDone=FALSE; | |
- | |
- while ((buf=bgets(HttpSock))) { | |
- if (HeaderDone) { | |
- NewServer=g_new0(ServerData,1); | |
- NewServer->Name=buf; | |
- buf=bgets(HttpSock); | |
- NewServer->Port=atoi(buf); g_free(buf); | |
- NewServer->Version=bgets(HttpSock); | |
- buf=bgets(HttpSock); | |
- if (buf[0]) NewServer->CurPlayers=atoi(buf); | |
- else NewServer->CurPlayers=-1; | |
- g_free(buf); | |
- buf=bgets(HttpSock); | |
- NewServer->MaxPlayers=atoi(buf); g_free(buf); | |
- NewServer->Update=bgets(HttpSock); | |
- NewServer->Comment=bgets(HttpSock); | |
- NewServer->UpSince=bgets(HttpSock); | |
- ServerList=g_slist_append(ServerList,NewServer); | |
- } else { | |
- if (strncmp(buf,"MetaServer:",11)==0) HeaderDone=TRUE; | |
- g_free(buf); | |
- } | |
- } | |
-} | |
-#endif /* NETWORKING */ | |
- | |
void SendFightReload(Player *To) { | |
SendFightMessage(To,NULL,0,F_RELOAD,(price_t)0,FALSE,NULL); | |
} | |
diff --git a/src/message.h b/src/message.h | |
t@@ -133,8 +133,7 @@ HttpConnection *OpenMetaHttpConnection(void); | |
void CloseHttpConnection(HttpConnection *conn); | |
gchar *ReadHttpResponse(HttpConnection *conn); | |
gboolean HandleWaitingMetaServerData(HttpConnection *conn); | |
- | |
-gchar *bgets(int fd); | |
+void ClearServerList(void); | |
#endif /* NETWORKING */ | |
extern GSList *FirstClient; | |
t@@ -168,12 +167,6 @@ int ProcessMessage(char *Msg,Player *Play,Player **Other,… | |
void ReceiveDrugsHere(char *text,Player *To); | |
gboolean HandleGenericClientMessage(Player *From,AICode AI,MsgCode Code, | |
Player *To,char *Data,DispMode *DisplayMode); | |
-#ifdef NETWORKING | |
-char *OpenMetaServerConnection(int *HttpSock); | |
-void CloseMetaServerConnection(int HttpSock); | |
-void ClearServerList(void); | |
-void ReadMetaServerData(int HttpSock); | |
-#endif | |
void InitAbilities(Player *Play); | |
void SendAbilities(Player *Play); | |
void ReceiveAbilities(Player *Play,gchar *Data); |