1
0
mirror of https://github.com/OpenTTD/OpenTTD.git synced 2025-08-23 14:39:08 +00:00

(svn r106) New network core (by sign_de)

Features:
* network core is dynamicly loaded when needed (-n isn't needed anymore) 
  for easy switching between single and multiplayer. But commandline 
  shortcuts are still enabled:
   -n = autodetect network server
   -n [ip] = connect to the server
* udp now uses 2 different ports
  - you can run 1 server and serveral clients on one pc
  - the clients udp-socket gets unloaded when the
    network game starts
  - the servers udp-sockets remains online to allow the
    network gui to detect itself
* new gameinfo structure
  this struct is available for every online/lan game
* dynamic NetworkGameList
This commit is contained in:
dominik
2004-08-22 10:23:37 +00:00
parent b2340212c3
commit 0bd907e88d
9 changed files with 691 additions and 278 deletions

View File

@@ -21,16 +21,6 @@ void ShowQueryString(StringID str, StringID caption, int maxlen, int maxwidth, b
static byte _selected_field;
char *direct_ip = NULL;
void ConnectToServer(byte* b)
{
_networking = true;
NetworkInitialize(b);
DEBUG(misc, 1) ("Connecting to %s %d\n", b, _network_port);
NetworkConnect(b, _network_port);
}
static const StringID _connection_types_dropdown[] = {
STR_NETWORK_LAN,
STR_NETWORK_INTERNET,
@@ -65,7 +55,15 @@ static void NetworkGameWindowWndProc(Window *w, WindowEvent *e)
case 0: // close X
case 15: // cancel button
DeleteWindowById(WC_NETWORK_WINDOW, 0);
NetworkLobbyShutdown();
break;
case 3: // find server automaticaly
{
byte *b = "auto";
NetworkCoreConnectGame(b,_network_server_port);
}
break;
case 4: // connect via direct ip
{
StringID str;
@@ -111,7 +109,7 @@ static void NetworkGameWindowWndProc(Window *w, WindowEvent *e)
byte *b = e->edittext.str;
if (*b == 0)
return;
ConnectToServer(b);
NetworkCoreConnectGame(b,_network_server_port);
} break;
}
@@ -159,6 +157,8 @@ void ShowNetworkGameWindow()
{
Window *w;
DeleteWindowById(WC_NETWORK_WINDOW, 0);
NetworkLobbyInit();
w = AllocateWindowDesc(&_network_game_window_desc);
strcpy(_edit_str_buf, "Your name");
@@ -168,24 +168,9 @@ void ShowNetworkGameWindow()
WP(w,querystr_d).maxlen = MAX_QUERYSTR_LEN;
WP(w,querystr_d).maxwidth = 240;
WP(w,querystr_d).buf = _edit_str_buf;
ShowErrorMessage(-1, TEMP_STRING_NO_NETWORK, 0, 0);
// ShowErrorMessage(-1, TEMP_STRING_NO_NETWORK, 0, 0);
}
void StartServer()
{
_networking = true;
NetworkInitialize(NULL);
DEBUG(misc, 1) ("Listening on port %d\n", _network_port);
NetworkListen(_network_port);
_networking_server = true;
DoCommandP(0, 0, 0, NULL, CMD_START_NEW_GAME);
}
static const StringID _players_dropdown[] = {
STR_NETWORK_2_PLAYERS,
STR_NETWORK_3_PLAYERS,
@@ -232,8 +217,9 @@ static void NetworkStartServerWindowWndProc(Window *w, WindowEvent *e)
ShowDropDownMenu(w, _players_dropdown, _opt_mod_ptr->currency, e->click.widget, 0);
return;
case 9: // start game
StartServer();
NetworkCoreStartGame();
ShowNetworkLobbyWindow();
DoCommandP(0, 0, 0, NULL, CMD_START_NEW_GAME);
break;
}
@@ -308,10 +294,6 @@ static void ShowNetworkStartServerWindow()
WP(w,querystr_d).buf = _edit_str_buf;
}
static void NetworkLobbyWindowWndProc(Window *w, WindowEvent *e)
{
switch(e->event) {