(svn r229) -Fix: Some more const stuff fixed .(Tron)
authordarkvater
Sun, 12 Sep 2004 23:35:01 +0000
changeset 228 f65dec6727d9
parent 227 5e7348ed8770
child 229 b94bfdf02bae
(svn r229) -Fix: Some more const stuff fixed .(Tron)
-Fix: ParseConnectionString() function to parse network connection string: <IP>[:<PORT>][#<PLAY_AS] .
console.c
console.h
console_cmds.c
network.c
network.h
network_gui.c
--- a/console.c	Sun Sep 12 22:29:33 2004 +0000
+++ b/console.c	Sun Sep 12 23:35:01 2004 +0000
@@ -436,7 +436,7 @@
 		}
 }
 
-void IConsoleVarMemRegister(byte * name, byte type) /* XXX TRON */
+void IConsoleVarMemRegister(const byte * name, byte type)
 {
 	_iconsole_var * item;
 	item = IConsoleVarAlloc(type);
--- a/console.h	Sun Sep 12 22:29:33 2004 +0000
+++ b/console.h	Sun Sep 12 23:35:01 2004 +0000
@@ -102,7 +102,7 @@
 // *** Variables *** //
 
 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);
 _iconsole_var * IConsoleVarGet(const byte * name);
 _iconsole_var * IConsoleVarAlloc(byte type);
@@ -124,5 +124,4 @@
 bool IConsoleVarHookHandle(_iconsole_var * hook_var, byte type);
 bool IConsoleCmdHookHandle(_iconsole_cmd * hook_cmd, byte type);
 
-
 #endif /* CONSOLE_H */
--- a/console_cmds.c	Sun Sep 12 22:29:33 2004 +0000
+++ b/console_cmds.c	Sun Sep 12 23:35:01 2004 +0000
@@ -96,43 +96,29 @@
 
 DEF_CONSOLE_CMD(ConNetworkConnect)
 {
-	byte * b;
-	byte * ip = NULL;
-	byte * port = NULL;
-	byte * player = NULL;
-	byte c;
+	byte * ip;
+	const byte *port = NULL;
+	const byte *player = NULL;
 	uint16 rport;
 
 	if (argc<2) return NULL;
 
-	b = argv[1];
+	ip = argv[1];
 	rport = _network_server_port;
-	c = 0;
-	ip = b;
 
-	while (b[c] != 0) {
-		if (((char)b[c]) == '#') {
-			player = &b[c+1];
-			b[c] = 0;
-			}
-		if (((char)b[c]) == ':') {
-			port = &b[c+1];
-			b[c] = 0;
-			}
-		c++;
-		}
+	ParseConnectionString(&player, &port, ip);
 
-	IConsolePrintF(_iconsole_color_default,"Connecting to %s...",ip);
+	IConsolePrintF(_iconsole_color_default,"Connecting to %s...", ip);
 	if (player!=NULL) {
 		_network_playas = atoi(player);
-		IConsolePrintF(_iconsole_color_default,"    player-no: %s",player);
+		IConsolePrintF(_iconsole_color_default,"    player-no: %s", player);
 	}
 	if (port!=NULL) {
 		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;
 }
--- a/network.c	Sun Sep 12 22:29:33 2004 +0000
+++ b/network.c	Sun Sep 12 23:35:01 2004 +0000
@@ -1653,6 +1653,22 @@
 
 /* *************************************************** */
 
+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)
 {
 	if (!_network_available) return false;
@@ -1901,6 +1917,7 @@
 void NetworkCoreShutdown() {};
 void NetworkCoreDisconnect() {};
 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 NetworkCoreStartGame() {return false;};
 void NetworkLobbyShutdown() {};
--- a/network.h	Sun Sep 12 22:29:33 2004 +0000
+++ b/network.h	Sun Sep 12 23:35:01 2004 +0000
@@ -27,4 +27,6 @@
 NetworkGameInfo _network_game;
 NetworkGameList * _network_game_list;
 
+void ParseConnectionString(const byte **player, const byte **port, byte *connection_string);
+
 #endif /* NETWORK_H */
--- a/network_gui.c	Sun Sep 12 22:29:33 2004 +0000
+++ b/network_gui.c	Sun Sep 12 23:35:01 2004 +0000
@@ -170,27 +170,13 @@
 	case WE_ON_EDIT_TEXT: {
 		byte *b = e->edittext.str;
 		if (*b != 0) {
-			byte * ip = NULL;
-			byte * port = NULL;
-			byte * player = NULL;
-			byte c;
+			const byte *port = NULL;
+			const byte *player = NULL;
 			uint16 rport;
 
 			rport = _network_server_port;
-			c = 0;
-			ip = b;
 
-			while (b[c] != 0) {
-				if (((char)b[c]) == '#') {
-					player = &b[c+1];
-					b[c] = 0;
-					}
-				if (((char)b[c]) == ':') {
-					port = &b[c+1];
-					b[c] = 0;
-					}
-				c++;
-				}
+			ParseConnectionString(&player, &port, b);
 
 			if (player!=NULL) _network_playas = atoi(player);
 			if (port!=NULL) rport = atoi(port);