[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Stratagus-CVS] stratagus data/ccl/menus.ccl src/include/master...
From: |
Russell Smith |
Subject: |
[Stratagus-CVS] stratagus data/ccl/menus.ccl src/include/master... |
Date: |
Tue, 14 Oct 2003 22:00:59 -0400 |
CVSROOT: /cvsroot/stratagus
Module name: stratagus
Branch:
Changes by: Russell Smith <address@hidden> 03/10/14 22:00:59
Modified files:
data/ccl : menus.ccl
src/include : master.h
src/network : master.c
src/ui : menus.c
Log message:
MetaServer work, reduce crashes, and clean command processing
Patches:
Index: stratagus/data/ccl/menus.ccl
diff -u stratagus/data/ccl/menus.ccl:1.91 stratagus/data/ccl/menus.ccl:1.92
--- stratagus/data/ccl/menus.ccl:1.91 Sat Oct 11 23:21:37 2003
+++ stratagus/data/ccl/menus.ccl Tue Oct 14 22:00:58 2003
@@ -26,7 +26,7 @@
;; along with this program; if not, write to the Free Software
;; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
USA
;;
-;; $Id: menus.ccl,v 1.91 2003/10/12 03:21:37 mr-russ Exp $
+;; $Id: menus.ccl,v 1.92 2003/10/15 02:00:58 mr-russ Exp $
;;
;; load the keystroke helps
@@ -579,7 +579,7 @@
'button '(size (224 27)
caption "~!Join Internet Game"
hotkey "j"
- func menu-multi-master-gem
+ func menu-metaserver-init
style gm-full)
'menu 'menu-internet-create-join-menu)
(define-menu-item 'pos (list 208 (+ 320 (* 36 1))) 'font 'large
Index: stratagus/src/include/master.h
diff -u stratagus/src/include/master.h:1.12 stratagus/src/include/master.h:1.13
--- stratagus/src/include/master.h:1.12 Tue Oct 14 18:44:31 2003
+++ stratagus/src/include/master.h Tue Oct 14 22:00:58 2003
@@ -26,7 +26,7 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
-// $Id: master.h,v 1.12 2003/10/14 22:44:31 jsalmon3 Exp $
+// $Id: master.h,v 1.13 2003/10/15 02:00:58 mr-russ Exp $
#ifndef __MASTER_H__
#define __MASTER_H__
@@ -59,5 +59,6 @@
extern int MetaServerOK(char* reply);
extern int SendMetaCommand(char* command, char* format, ...);
extern int RecvMetaReply(char** reply);
+extern int GetMetaParameter(char* reply, int pos, char** value);
#endif // !__MASTER_H__
Index: stratagus/src/network/master.c
diff -u stratagus/src/network/master.c:1.16 stratagus/src/network/master.c:1.17
--- stratagus/src/network/master.c:1.16 Tue Oct 14 18:44:31 2003
+++ stratagus/src/network/master.c Tue Oct 14 22:00:58 2003
@@ -26,7 +26,7 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
-// $Id: master.c,v 1.16 2003/10/14 22:44:31 jsalmon3 Exp $
+// $Id: master.c,v 1.17 2003/10/15 02:00:58 mr-russ Exp $
//@{
@@ -145,6 +145,42 @@
return !strcmp("OK\r\n", reply) || !strcmp("OK\n", reply);
}
+/** Retrieves the value of the parameter at position paramNumber
+**
+** @param reply The reply from the metaserver
+** @param pos the parameter number
+** @param value the returned value
+**
+** @returns -1 if error.
+*/
+global int GetMetaParameter(char* reply, int pos, char** value)
+{
+ char* endline;
+
+ *value = reply;
+
+ while (pos-- && *value) {
+ *value = strstr(*value,"\n");
+ }
+
+ if (!*value) {
+ // Parameter our of bounds
+ return -1;
+ }
+
+ endline = strstr(*value,"\n");
+
+ if (!endline) {
+ return -1;
+ }
+
+ *endline = '\0';
+ *value = strdup(*value);
+ *endline = '\n';
+ return 0;
+}
+
+
/**
** Send a command to the meta server
**
@@ -238,12 +274,17 @@
}
p = NULL;
-
+
+ // FIXME: Allow for large packets
n = NetRecvTCP(sockfd, &buf, 1024);
if (!(p = malloc(n + 1))) {
return -1;
}
- buf[n] = '\0';
+
+ // We know we now have the whole command.
+ // Convert to standard notation
+ buf[n-1] = '\0';
+ buf[n-2] = '\n';
strcpy(p, buf);
*reply = p;
Index: stratagus/src/ui/menus.c
diff -u stratagus/src/ui/menus.c:1.562 stratagus/src/ui/menus.c:1.563
--- stratagus/src/ui/menus.c:1.562 Tue Oct 14 18:44:31 2003
+++ stratagus/src/ui/menus.c Tue Oct 14 22:00:58 2003
@@ -26,7 +26,7 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
-// $Id: menus.c,v 1.562 2003/10/14 22:44:31 jsalmon3 Exp $
+// $Id: menus.c,v 1.563 2003/10/15 02:00:58 mr-russ Exp $
//@{
@@ -3193,7 +3193,9 @@
VideoUnlockScreen();
Invalidate();
- SendMetaCommand("StartGame","");
+ if (MetaServerInUse) {
+ SendMetaCommand("StartGame","");
+ }
GameSettings.Presets[0].Race = SettingsPresetMapDefault;
@@ -7292,38 +7294,61 @@
int k;
int numparams;
int nummenus;
+ char* parameter;
char* reply;
-
- SendMetaCommand("GameList", "");
+ Menu *menu;
+
+ SendMetaCommand("NumberOfGames","");
+ menu = FindMenu("menu-metaserver-list");
+
reply = NULL;
//receive
//check okay
-
+ if (1 || RecvMetaReply(&reply) == -1) {
+ //TODO: Notify player that connection was aborted...
+ nummenus = 1;
+
+
+ } else {
+ GetMetaParameter(reply, 1, ¶meter);
+ nummenus = atoi(parameter);
+ }
// Meta server only sends matching version
// Only Displays games from Matching version
- nummenus = 5;
- i = 1;
- k = 0;
- numparams = 4; //TODO: To be changed if more params are sent
+
- //Retrieve list of online game from the meta server
- for (j = 4; j <= nummenus * (numparams + 1); j += numparams + 1) { //
loop over the number of items in the menu
- //TODO: hard coded.
- // Check if connection to meta server is there.
- SendMetaCommand("NextGameInList", "");
- i = RecvMetaReply(&reply);
- if (i == 0) {
- // fill the menus with the right info.
- mi->menu->Items[j].d.text.text = "Nick";
- mi->menu->Items[j + 1].d.text.text = "IP";
- mi->menu->Items[j + 2].d.text.text = "OS";
- mi->menu->Items[j + 3].d.text.text = "Engine Version";
- }
- ++k;
- }
- // mi->menu->Items[4].d.text.text=TheMessage->Nickname;
- // mi->menu->Items[9].d.text.text=TheMessage->Nickname;
- // mi->menu->Items[14].d.text.text=TheMessage->Nickname;
+ i = 1;
+ k = 0;
+ numparams = 4; //TODO: To be changed if more params are sent
+
+ //Retrieve list of online game from the meta server
+ for (j = 4; j <= nummenus * (numparams + 1); j += numparams + 1) { // loop
over the number of items in the menu
+ //TODO: hard coded.
+ // Check if connection to meta server is there.
+
+ SendMetaCommand("GameNumber","%d\n",k + 1);
+ i=RecvMetaReply(&reply);
+
+
+ if (i == 0) {
+ // fill the menus with the right info.
+
+ menu->Items[j].d.text.text = "Nick";
+ menu->Items[j + 1].d.text.text = "IP";
+ menu->Items[j + 2].d.text.text = "OS";
+ menu->Items[j + 3].d.text.text = "Engine Version";
+ } else {
+ GetMetaParameter(reply, 0, ¶meter); ////TODO: use this
function.
+ menu->Items[j].d.text.text = parameter;
+ GetMetaParameter(reply, 1, ¶meter);
+ menu->Items[j + 1].d.text.text = parameter;
+ GetMetaParameter(reply, 2, ¶meter);
+ menu->Items[j + 2].d.text.text = parameter;
+ GetMetaParameter(reply, 3, ¶meter);
+ menu->Items[j + 3].d.text.text = parameter;
+ }
+ ++k;
+ }
}
/**
@@ -7404,19 +7429,19 @@
/**
** Action to add a game server on the meta-server.
*/
-local void AddGameServer()
+local void AddGameServer(void)
{
//send message to meta server. meta server will detect IP address.
//Meta-server will return "BUSY" if the list of online games is busy.
-
SendMetaCommand("AddGame","%s\n%s\n%s\n%s\n","Name","Map","Players","Free");
+
SendMetaCommand("AddGame","%s\n%s\n%s\n%s\n%s\n%s\n","IP","Port","Name","Map","Players","Free");
// FIXME: Get Reply from Queue
}
-local int MetaServerConnectError()
+local int MetaServerConnectError(void)
{
Invalidate();
NetErrorMenu("Cannot Connect to Meta-Server");