(svn r229) -Fix: Some more const stuff fixed .(Tron)

-Fix: ParseConnectionString() function to parse network connection string: <IP>[:<PORT>][#<PLAY_AS] .
This commit is contained in:
darkvater 2004-09-12 23:35:01 +00:00
parent ec21a64c03
commit 01dd0219d3
6 changed files with 33 additions and 43 deletions

View File

@ -436,7 +436,7 @@ void IConsoleVarRegister(const byte * name, void * addr, byte type)
} }
} }
void IConsoleVarMemRegister(byte * name, byte type) /* XXX TRON */ void IConsoleVarMemRegister(const byte * name, byte type)
{ {
_iconsole_var * item; _iconsole_var * item;
item = IConsoleVarAlloc(type); item = IConsoleVarAlloc(type);

View File

@ -102,7 +102,7 @@ void* IConsoleCmdGetAddr(byte * name);
// *** Variables *** // // *** Variables *** //
void IConsoleVarRegister(const byte * name, void * addr, byte type); void IConsoleVarRegister(const byte * name, void * addr, byte type);
void IConsoleVarMemRegister(byte * name, byte type); void IConsoleVarMemRegister(const byte * name, byte type);
void IConsoleVarInsert(_iconsole_var * var, const byte * name); void IConsoleVarInsert(_iconsole_var * var, const byte * name);
_iconsole_var * IConsoleVarGet(const byte * name); _iconsole_var * IConsoleVarGet(const byte * name);
_iconsole_var * IConsoleVarAlloc(byte type); _iconsole_var * IConsoleVarAlloc(byte type);
@ -124,5 +124,4 @@ void IConsoleCmdHook(const byte * name, byte type, void * proc);
bool IConsoleVarHookHandle(_iconsole_var * hook_var, byte type); bool IConsoleVarHookHandle(_iconsole_var * hook_var, byte type);
bool IConsoleCmdHookHandle(_iconsole_cmd * hook_cmd, byte type); bool IConsoleCmdHookHandle(_iconsole_cmd * hook_cmd, byte type);
#endif /* CONSOLE_H */ #endif /* CONSOLE_H */

View File

@ -96,43 +96,29 @@ DEF_CONSOLE_CMD(ConScrollToTile)
DEF_CONSOLE_CMD(ConNetworkConnect) DEF_CONSOLE_CMD(ConNetworkConnect)
{ {
byte * b; byte * ip;
byte * ip = NULL; const byte *port = NULL;
byte * port = NULL; const byte *player = NULL;
byte * player = NULL;
byte c;
uint16 rport; uint16 rport;
if (argc<2) return NULL; if (argc<2) return NULL;
b = argv[1]; ip = argv[1];
rport = _network_server_port; rport = _network_server_port;
c = 0;
ip = b;
while (b[c] != 0) { ParseConnectionString(&player, &port, ip);
if (((char)b[c]) == '#') {
player = &b[c+1];
b[c] = 0;
}
if (((char)b[c]) == ':') {
port = &b[c+1];
b[c] = 0;
}
c++;
}
IConsolePrintF(_iconsole_color_default,"Connecting to %s...",ip); IConsolePrintF(_iconsole_color_default,"Connecting to %s...", ip);
if (player!=NULL) { if (player!=NULL) {
_network_playas = atoi(player); _network_playas = atoi(player);
IConsolePrintF(_iconsole_color_default," player-no: %s",player); IConsolePrintF(_iconsole_color_default," player-no: %s", player);
} }
if (port!=NULL) { if (port!=NULL) {
rport = atoi(port); rport = atoi(port);
IConsolePrintF(_iconsole_color_default," port: %s",port); IConsolePrintF(_iconsole_color_default," port: %s", port);
} }
NetworkCoreConnectGame(b, rport); NetworkCoreConnectGame(ip, rport);
return NULL; return NULL;
} }

View File

@ -1653,6 +1653,22 @@ void NetworkCoreShutdown()
/* *************************************************** */ /* *************************************************** */
void ParseConnectionString(const byte **player, const byte **port, byte *connection_string)
{
byte c = 0;
while (connection_string[c] != '\0') {
if (connection_string[c] == '#') {
*player = &connection_string[c+1];
connection_string[c] = '\0';
}
if (connection_string[c] == ':') {
*port = &connection_string[c+1];
connection_string[c] = '\0';
}
c++;
}
}
bool NetworkCoreConnectGame(const byte* b, unsigned short port) bool NetworkCoreConnectGame(const byte* b, unsigned short port)
{ {
if (!_network_available) return false; if (!_network_available) return false;
@ -1901,6 +1917,7 @@ void NetworkCoreInit() { _network_available=false; };
void NetworkCoreShutdown() {}; void NetworkCoreShutdown() {};
void NetworkCoreDisconnect() {}; void NetworkCoreDisconnect() {};
void NetworkCoreLoop(bool incomming) {}; void NetworkCoreLoop(bool incomming) {};
void ParseConnectionString(const byte **player, const byte **port, byte *connection_string) {};
bool NetworkCoreConnectGame(const byte* b, unsigned short port) {return false;}; bool NetworkCoreConnectGame(const byte* b, unsigned short port) {return false;};
bool NetworkCoreStartGame() {return false;}; bool NetworkCoreStartGame() {return false;};
void NetworkLobbyShutdown() {}; void NetworkLobbyShutdown() {};

View File

@ -27,4 +27,6 @@ typedef struct NetworkGameList {
NetworkGameInfo _network_game; NetworkGameInfo _network_game;
NetworkGameList * _network_game_list; NetworkGameList * _network_game_list;
void ParseConnectionString(const byte **player, const byte **port, byte *connection_string);
#endif /* NETWORK_H */ #endif /* NETWORK_H */

View File

@ -170,27 +170,13 @@ static void NetworkGameWindowWndProc(Window *w, WindowEvent *e)
case WE_ON_EDIT_TEXT: { case WE_ON_EDIT_TEXT: {
byte *b = e->edittext.str; byte *b = e->edittext.str;
if (*b != 0) { if (*b != 0) {
byte * ip = NULL; const byte *port = NULL;
byte * port = NULL; const byte *player = NULL;
byte * player = NULL;
byte c;
uint16 rport; uint16 rport;
rport = _network_server_port; rport = _network_server_port;
c = 0;
ip = b;
while (b[c] != 0) { ParseConnectionString(&player, &port, b);
if (((char)b[c]) == '#') {
player = &b[c+1];
b[c] = 0;
}
if (((char)b[c]) == ':') {
port = &b[c+1];
b[c] = 0;
}
c++;
}
if (player!=NULL) _network_playas = atoi(player); if (player!=NULL) _network_playas = atoi(player);
if (port!=NULL) rport = atoi(port); if (port!=NULL) rport = atoi(port);