[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Stratagus-CVS] stratagus doc/ChangeLog.html src/include/master...
From: |
Russell Smith |
Subject: |
[Stratagus-CVS] stratagus doc/ChangeLog.html src/include/master... |
Date: |
Sat, 11 Oct 2003 02:43:46 -0400 |
CVSROOT: /cvsroot/stratagus
Module name: stratagus
Branch:
Changes by: Russell Smith <address@hidden> 03/10/11 02:43:46
Modified files:
doc : ChangeLog.html
src/include : master.h
src/network : master.c network.c
src/ui : menus.c
src/video : sdl.c
Log message:
Remove Old MetaServer code, Began implementation of new code.
Patches:
Index: stratagus/doc/ChangeLog.html
diff -u stratagus/doc/ChangeLog.html:1.552 stratagus/doc/ChangeLog.html:1.553
--- stratagus/doc/ChangeLog.html:1.552 Thu Oct 9 19:15:26 2003
+++ stratagus/doc/ChangeLog.html Sat Oct 11 02:43:45 2003
@@ -2,7 +2,7 @@
<html>
<head>
<!--
----- $Id: ChangeLog.html,v 1.552 2003/10/09 23:15:26 mr-russ Exp $
+---- $Id: ChangeLog.html,v 1.553 2003/10/11 06:43:45 mr-russ Exp $
---- (c) Copyright 1998-2003 by Lutz Sammer
@@ -36,6 +36,7 @@
<li>Future 2.00 Release<p>
<ul>
<li>++
+ <li>Remove old Master Server Code, began implementing a new one (from
Russell Smith).
<li>Finished Support for units with MinAttackRange >1 Moving away to
attacker (from Russell Smith).
<li>Added Patch #1987: Fix for air/ground transporters. (from pludov).
<li>NEW_UI: Giving it up, removed #ifdef, saved patch in contrib/ (from
Martin Renold).
Index: stratagus/src/include/master.h
diff -u stratagus/src/include/master.h:1.8 stratagus/src/include/master.h:1.9
--- stratagus/src/include/master.h:1.8 Fri Jul 11 10:35:30 2003
+++ stratagus/src/include/master.h Sat Oct 11 02:43:45 2003
@@ -26,7 +26,7 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
-// $Id: master.h,v 1.8 2003/07/11 14:35:30 n0body Exp $
+// $Id: master.h,v 1.9 2003/10/11 06:43:45 mr-russ Exp $
#ifndef __MASTER_H__
#define __MASTER_H__
@@ -48,32 +48,14 @@
-- Declarations
----------------------------------------------------------------------------*/
- /// FIXME: docu
-extern char MasterTempString[50];
- /// FIXME: docu
-extern int PublicMasterAnnounce;
- /// FIXME: docu
-extern unsigned long LastTimeAnnounced;
- /// FIXME: docu
-extern int MasterPort;
- /// FIXME: docu
-extern unsigned long MasterHost;
- /// FIXME: docu
-extern char *MasterHostString;
-
/*----------------------------------------------------------------------------
-- Variables
----------------------------------------------------------------------------*/
- /// FIXME: docu
-extern int MasterInit(void);
- /// FIXME: docu
-extern void MasterLoop(unsigned long ticks);
- /// FIXME: docu
-extern void MasterSendAnnounce(void);
- /// FIXME: docu
-extern void MasterProcessGetServerData(const char* msg, size_t length,
unsigned long host, int port);
-
-//@}
+extern int MetaInit(void);
+extern int MetaClose(void);
+extern int MetaServerOK(char **reply);
+extern int SendMetaCommand(char* command, char* format, ...);
+extern int RecvMetaReply(char **reply);
#endif // !__MASTER_H__
Index: stratagus/src/network/master.c
diff -u stratagus/src/network/master.c:1.9 stratagus/src/network/master.c:1.10
--- stratagus/src/network/master.c:1.9 Wed Oct 1 21:37:06 2003
+++ stratagus/src/network/master.c Sat Oct 11 02:43:45 2003
@@ -26,7 +26,7 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
-// $Id: master.c,v 1.9 2003/10/02 01:37:06 jsalmon3 Exp $
+// $Id: master.c,v 1.10 2003/10/11 06:43:45 mr-russ Exp $
//@{
@@ -37,6 +37,7 @@
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
+#include <stdarg.h>
#include <ctype.h>
#include <limits.h>
@@ -48,29 +49,9 @@
#include "iocompat.h"
-#include "video.h"
-#include "player.h"
-#include "font.h"
-#include "tileset.h"
-#include "map.h"
-#include "minimap.h"
-#include "interface.h"
-#include "menus.h"
-#include "cursor.h"
-#include "pud.h"
-#include "iolib.h"
#include "network.h"
#include "netconnect.h"
-#include "settings.h"
-#include "ui.h"
-#include "campaign.h"
-#include "sound_server.h"
-#include "sound.h"
#include "ccl.h"
-#include "editor.h"
-#include "commands.h"
-#include "actions.h"
-
#include "master.h"
// FIXME: jim4: why is this defined?
@@ -86,142 +67,183 @@
-- Variables
----------------------------------------------------------------------------*/
-#define MASTER_REFRESHRATE 25000
-
-global char MasterTempString[50]; /// FIXME: docu
-global int PublicMasterAnnounce; /// FIXME: docu
-global unsigned long LastTimeAnnounced; /// FIXME: docu
-global int MasterPort; /// FIXME: docu
-global unsigned long MasterHost; /// FIXME: docu
-global char* MasterHostString; /// FIXME: docu
-
-local int sock; /// FIXME: docu
-local char challenge[12]; /// FIXME: docu
+//###### For Magnant META SERVER
+local int sockfd; // This is a TCP socket.
/*----------------------------------------------------------------------------
-- Functions
----------------------------------------------------------------------------*/
+
/**
-** FIXME: docu
-*/
-global int MasterInit(void)
-{
- sock = NetworkFildes;
- MasterHostString = strdup(MASTER_HOST);
- MasterHost = NetResolveHost(MasterHostString);
- MasterPort = htons(MASTER_PORT);
- if (!sock) {
- PublicMasterAnnounce = 0;
+** Initialize the TCP connection to the Meta Server.
+**
+** @return -1 fail, 0 success.
+*/
+global int MetaInit(void)
+{
+ int TCPConnectStatus; // = 0 if not successful, -1 if not.
+ int i;
+ char** reply;
+
+ reply = NULL;
+ sockfd = NetworkFildes;
+ for (i = 1234; i < 1244; ++i) {
+ sockfd=NetOpenTCP(i); //FIXME: need to make a dynamic port allocation
there...if (!sockfd) {...}
+ if (sockfd != -1) {
+ break;
+ }
+ }
+
+ // FIXME: Configurable Meta Server
+ TCPConnectStatus =
NetConnectTCP(sockfd,NetResolveHost(MASTER_HOST),MASTER_PORT);
+
+ if (TCPConnectStatus == -1) {
+ //TODO: Notify player that connection was aborted...
+ return -1;
+ }
+
+ if (SendMetaCommand("Login","") == -1) {
+ //TODO: Notify player that connection was aborted...
return -1;
}
- return 0;
-}
-/**
-** FIXME: docu
-*/
-local int MasterSend(const void* buf, int len)
-{
- return NetSendUDP(sock, MasterHost, MasterPort, buf, len);
+ if (RecvMetaReply(reply) == -1) {
+ //TODO: Notify player that connection was aborted...
+ return -1;
+ } else {
+ if (MetaServerOK(reply)) {
+ free(*reply);
+ return 0;
+ } else {
+ free(*reply);
+ return -1;
+ }
+ }
+
+ return 0;
}
-/**
-** FIXME: docu
+/** Close Connection to Master Server
+**
+** @return nothing
*/
-global void MasterSendAnnounce(void)
+global int MetaClose(void)
{
- char *heartbeat = "\xFF\xFF\xFF\xFFheartbeat Stratagus\x0A";
-
- MasterSend(heartbeat, strlen(heartbeat));
+ NetCloseTCP(sockfd);
+ return 0;
}
/**
-** FIXME: docu
+** Checks if a Message was OK or ERR
+**
+** @return 1 OK, 0 Error.
*/
-local void MasterSendInfo(void)
+global int MetaServerOK(char **reply)
{
- char sendinfo[1000];
- int numplayers;
- int mapmaxplayers;
- int closedslots;
- int i;
-
- mapmaxplayers = 0;
- closedslots = 0;
- for (i = 0; i < PlayerMax; ++i) {
- if (MenuMapInfo->PlayerType[i] == PlayerPerson) {
- if (ServerSetupState.CompOpt[i] == 2) {
- ++closedslots;
- } else {
- ++mapmaxplayers;
- }
- }
- }
-
- numplayers = 1;
- for (i = 0; i < mapmaxplayers + numplayers; ++i) {
- if (Hosts[i].PlyNr) {
- ++numplayers;
- }
- }
- numplayers += mapmaxplayers - NetPlayers;
-
- sprintf(sendinfo,
"\xFF\xFF\xFF\xFFinfoResponse\x0A\\protocol\\%d:%d\\gamehost\\%s\\clients\\%d\\sv_maxclients\\%d\\gamename\\%s\\challenge\\%s",
- StratagusVersion, NetworkProtocolVersion, LocalPlayerName, numplayers,
- mapmaxplayers, MenuMapInfo->Description, challenge);
- MasterSend(sendinfo, strlen(sendinfo));
+ return !strcmp("OK",*reply);
}
/**
-** FIXME: docu
+** Send a command to the meta server
+**
+** @param command command to send
+** @param format format of parameters
+** @param ... parameters
+**
+** @returns -1 fail, length of command
*/
-global void MasterProcessGetServerData(const char* msg, size_t length,
- unsigned long host, int port)
+global int SendMetaCommand(char* command, char* format, ...)
{
- if (!PublicMasterAnnounce || !sock) {
- return;
+ int n;
+ int size;
+ int ret;
+ char* p;
+ char* s;
+ va_list ap;
+
+ size = strlen(GameName)+strlen(LocalPlayerName)+strlen(command)+100;
+ ret = -1;
+ if ((p = malloc(size)) == NULL) {
+ return -1;
}
- if (!strncmp(msg, "getinfo ", 8)) {
- //if (host == NetResolveHost(MasterHost)) {
- {
- strncpy(challenge, msg + 8, sizeof(challenge));
- challenge[11] = '\0';
- MasterSendInfo();
+ // Message Structure
+ // Player Name, Game Name, VERSION, Command, **Paramaters**
+ strcpy(p, LocalPlayerName);
+ strcat(p, "\n");
+ strcat(p, GameName);
+ strcat(p, "\n");
+ strcat(p, VERSION);
+ strcat(p, "\n");
+ strcat(p, command);
+ strcat(p, "\n");
+
+ // Commands
+ // Login - 1, password
+ // Logout - 0
+ // AddGame - ,Name,Map,Players,FreeSpots
+ // JoinGame - Nick of Host
+ // ChangeGame - ,Name,Map,Players,FreeSpots
+ // GameList - 0
+ // NextGameInList - 0
+ // StartGame - 0
+ // PlayerScore - Score,Win (Add razings...)
+ // EndGame - Called after PlayerScore.
+ // AbandonGame - 0
+ while (1) {
+ /* Try to print in the allocated space. */
+ va_start(ap, format);
+ s = va_arg(ap, char *);
+ n = vsnprintf(p, size, format, ap);
+ va_end(ap);
+ /* If that worked, string was processed. */
+ if (n > -1 && n < size) {
+ break;
+ }
+ /* Else try again with more space. */
+ if (n > -1) { /* glibc 2.1 */
+ size = n + 1; /* precisely what is needed */
+ } else { /* glibc 2.0 */
+ size *= 2; /* twice the old size */
+ }
+ if ((p = realloc(p, size)) == NULL) {
+ return -1;
}
}
+ // Allocate the correct size
+ size = strlen(p);
+ ret = NetSendTCP(sockfd, p, size);
+ free(p);
+ return ret;
}
/**
-** FIXME: docu
+** Receive reply from Meta Server
+**
+** @param reply Text of the reply
+** @return error or number of bytes
*/
-local void MasterStopAnnounced(void)
+global int RecvMetaReply(char **reply)
{
- MasterSendAnnounce();
-}
+ int n;
+ int size;
+ char *p;
+ char buf[1024];
-/**
-** FIXME: docu
-*/
-global void MasterLoop(unsigned long ticks)
-{
- if (!PublicMasterAnnounce || !sock) {
- return;
+ if (NetSocketReady(sockfd, 5000) == -1) {
+ return -1;
}
-
- if (LastTimeAnnounced &&
- ticks <= LastTimeAnnounced + MASTER_REFRESHRATE) {
- return;
+
+ size=1;
+ while ((n = NetRecvTCP(sockfd, &buf, 1024))) {
+ size += n;
+ if ((p = realloc(p, size)) == NULL) {
+ return -1;
+ }
+ strcat(p, buf);
}
- LastTimeAnnounced = ticks;
- if (PublicMasterAnnounce == 2) {
- MasterStopAnnounced();
- PublicMasterAnnounce = 0;
- return;
- }
- MasterSendAnnounce();
+ reply = &p;
+ return size;
}
-
-//@}
Index: stratagus/src/network/network.c
diff -u stratagus/src/network/network.c:1.119
stratagus/src/network/network.c:1.120
--- stratagus/src/network/network.c:1.119 Thu Oct 9 07:31:47 2003
+++ stratagus/src/network/network.c Sat Oct 11 02:43:45 2003
@@ -26,7 +26,7 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
-// $Id: network.c,v 1.119 2003/10/09 11:31:47 n0body Exp $
+// $Id: network.c,v 1.120 2003/10/11 06:43:45 mr-russ Exp $
//@{
@@ -689,12 +689,6 @@
DebugLevel0("Server/Client gone?\n");
// just hope for an automatic recover right now..
NetworkInSync = 0;
- return;
- }
-
- if (!strncmp(buf, "\xFF\xFF\xFF\xFFgetinfo", 11))
- {
- MasterProcessGetServerData(buf + 4, i - 4, NetLastHost, NetLastPort);
return;
}
Index: stratagus/src/ui/menus.c
diff -u stratagus/src/ui/menus.c:1.559 stratagus/src/ui/menus.c:1.560
--- stratagus/src/ui/menus.c:1.559 Mon Sep 29 22:53:02 2003
+++ stratagus/src/ui/menus.c Sat Oct 11 02:43:46 2003
@@ -26,7 +26,7 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
-// $Id: menus.c,v 1.559 2003/09/30 02:53:02 jsalmon3 Exp $
+// $Id: menus.c,v 1.560 2003/10/11 06:43:46 mr-russ Exp $
//@{
@@ -769,8 +769,6 @@
HASHADD(ReplayGameCancel,"replay-game-cancel");
// Metaserver
- HASHADD(EnterMasterAction,"enter-master-action");
- HASHADD(MultiGameMasterReport,"menu-multi-master-gem");
}
/*----------------------------------------------------------------------------
@@ -2764,10 +2762,6 @@
ScenSelectMenu();
MultiGamePlayerSelectorsUpdate(1);
- if (PublicMasterAnnounce) {
- MasterSendAnnounce();
- }
-
menu->Items[6].flags = MI_DISABLED;
}
@@ -3153,18 +3147,10 @@
Menu *menu;
menu = FindMenu("menu-multi-setup");
- menu->Items[61].d.input.buffer = MasterTempString;
- sprintf(MasterTempString, "%s:%d", MasterHostString, ntohs(MasterPort));
- strcat(MasterTempString, "~!_");
- menu->Items[61].d.input.nch = strlen(MasterTempString) - 3;
- menu->Items[61].d.input.maxch = 49;
- PublicMasterAnnounce = 0;
- menu->Items[60].d.gem.state = MI_GSTATE_UNCHECKED;
DestroyCursorBackground();
GuiGameStarted = 0;
ProcessMenu("menu-multi-setup", 1);
- PublicMasterAnnounce = 2;
if (GuiGameStarted) {
GameMenuReturn();
}
@@ -7196,73 +7182,6 @@
fclose(fd);
}
#endif
-}
-
-/**
-** FIXME: docu
-*/
-local void MultiGameMasterReport(void)
-{
- Menu *menu;
- char *port;
- char ch;
-
- menu = FindMenu("menu-multi-setup");
- if (menu->Items[61].d.input.nch == 0) {
- PublicMasterAnnounce = 0;
- menu->Items[60].d.gem.state = MI_GSTATE_UNCHECKED;
- return;
- }
-
- ch = MasterTempString[menu->Items[61].d.input.nch];
- MasterTempString[menu->Items[61].d.input.nch] = '\0';
- port = strchr(MasterTempString, ':');
- if (port) {
- *port = '\0';
- ++port;
- if (MasterHostString) {
- free(MasterHostString);
- }
- MasterHostString = strdup(MasterTempString);
- MasterHost = NetResolveHost(MasterHostString);
- MasterPort = htons(atoi(port));
- --port;
- *port = ':';
- } else {
- if (MasterHostString) {
- free(MasterHostString);
- }
- MasterHostString = strdup(MasterTempString);
- MasterHost = NetResolveHost(MasterHostString);
- MasterPort = htons(MASTER_PORT);
- }
-
- if (PublicMasterAnnounce) {
- PublicMasterAnnounce = 0;
- menu->Items[60].d.gem.state = MI_GSTATE_UNCHECKED;
- // change behaviour here?
- MasterSendAnnounce();
- } else {
- PublicMasterAnnounce = 1;
- menu->Items[60].d.gem.state = MI_GSTATE_CHECKED;
- MasterSendAnnounce();
- }
-
- MasterTempString[menu->Items[61].d.input.nch] = ch;
-}
-
-/**
-** FIXME: docu
-*/
-local void EnterMasterAction(Menuitem *mi, int key)
-{
- Menu *menu;
-
- if (key == '\b' || (key >= ' ' && key <= 256)) {
- menu = FindMenu("menu-multi-setup");
- PublicMasterAnnounce = 0;
- menu->Items[60].d.gem.state = MI_GSTATE_UNCHECKED;
- }
}
//@}
Index: stratagus/src/video/sdl.c
diff -u stratagus/src/video/sdl.c:1.99 stratagus/src/video/sdl.c:1.100
--- stratagus/src/video/sdl.c:1.99 Tue Oct 7 20:06:44 2003
+++ stratagus/src/video/sdl.c Sat Oct 11 02:43:46 2003
@@ -26,7 +26,7 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
-// $Id: sdl.c,v 1.99 2003/10/08 00:06:44 jsalmon3 Exp $
+// $Id: sdl.c,v 1.100 2003/10/11 06:43:46 mr-russ Exp $
//@{
@@ -75,9 +75,6 @@
#include "sound.h"
#include "interface.h"
-// FIXME: needs to be moved to better location
-#include "master.h"
-
/*----------------------------------------------------------------------------
-- Declarations
----------------------------------------------------------------------------*/
@@ -687,9 +684,6 @@
}
NextFrameTicks += FrameTicks;
}
-
- // FIXME: move to better location
- MasterLoop(ticks);
//
// Prepare select
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Stratagus-CVS] stratagus doc/ChangeLog.html src/include/master...,
Russell Smith <=