diff options
author | darkvater <darkvater@openttd.org> | 2004-08-10 14:14:00 +0000 |
---|---|---|
committer | darkvater <darkvater@openttd.org> | 2004-08-10 14:14:00 +0000 |
commit | 804f038594ccd7d12b776299038f9bc5809f90e5 (patch) | |
tree | 55ef141185c7dd684c505675aec96c660a9bae71 | |
parent | efaeb275f78e18d594d9ee8ff04eccd2dc59512c (diff) | |
download | openttd-804f038594ccd7d12b776299038f9bc5809f90e5.tar.xz |
(svn r2) -Fix [993829] UDP Fixes (lucaspiller)
-Fix change 255/0xFF to OWNER_SPECTATOR for
spectator stuff (TrueLight)
-rw-r--r-- | functions.h | 2 | ||||
-rw-r--r-- | main_gui.c | 8 | ||||
-rw-r--r-- | network.c | 20 | ||||
-rw-r--r-- | network_gui.c | 4 | ||||
-rw-r--r-- | players.c | 4 | ||||
-rw-r--r-- | screenshot.c | 2 | ||||
-rw-r--r-- | town_gui.c | 2 | ||||
-rw-r--r-- | ttd.c | 16 | ||||
-rw-r--r-- | ttd.h | 7 |
9 files changed, 41 insertions, 24 deletions
diff --git a/functions.h b/functions.h index 4695e7681..f203887ec 100644 --- a/functions.h +++ b/functions.h @@ -126,7 +126,7 @@ void NetworkReceive(); void NetworkSend(); void NetworkProcessCommands(); void NetworkListen(int port); -void NetworkInitialize(); +void NetworkInitialize(const char *hostname); void NetworkShutdown(); void NetworkSendCommand(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, CommandCallback *callback); void NetworkStartSync(); diff --git a/main_gui.c b/main_gui.c index 5ab08aece..5dbeabf2f 100644 --- a/main_gui.c +++ b/main_gui.c @@ -597,7 +597,7 @@ static Window *PopupMainPlayerToolbMenu(Window *w, int x, int main_button, int g w = AllocateWindow(x, 0x16, 0xF1, 0x52, PlayerMenuWndProc, WC_TOOLBAR_MENU, _player_menu_widgets); w->flags4 &= ~WF_WHITE_BORDER_MASK; WP(w,menu_d).item_count = 0; - WP(w,menu_d).sel_index = _local_player != 0xff ? _local_player : 0; + WP(w,menu_d).sel_index = _local_player != OWNER_SPECTATOR ? _local_player : 0; WP(w,menu_d).action_id = main_button; WP(w,menu_d).main_button = main_button; WP(w,menu_d).checked_items = gray; @@ -1633,7 +1633,7 @@ static void MainToolbarWndProc(Window *w, WindowEvent *e) GfxFillRect(0, 0, w->width-1, w->height-1, 0x80B4); // if spectator, disable things - if (_current_player == 0xff){ + if (_current_player == OWNER_SPECTATOR){ w->disabled_state |= (1 << 0) | (1 << 19) | (1<<20) | (1<<21) | (1<<22) | (1<<23); } else { w->disabled_state &= ~((1 << 0) | (1 << 19) | (1<<20) | (1<<21) | (1<<22) | (1<<23)); @@ -1965,7 +1965,7 @@ void StatusBarWndProc(Window *w, WindowEvent *e) SET_DPARAM16(0, _date); DrawStringCentered(70, 1, ((_pause||_patches.status_long_date)?STR_00AF:STR_00AE), 0); - p = _local_player == 0xff ? NULL : DEREF_PLAYER(_local_player); + p = _local_player == OWNER_SPECTATOR ? NULL : DEREF_PLAYER(_local_player); if (p) { // Draw player money @@ -1996,7 +1996,7 @@ void StatusBarWndProc(Window *w, WindowEvent *e) if (e->click.widget == 1) { ShowLastNewsMessage(); } else if (e->click.widget == 2) { - if (_local_player != 0xff) ShowPlayerFinances(_local_player); + if (_local_player != OWNER_SPECTATOR) ShowPlayerFinances(_local_player); } else { ResetObjectToPlace(); } @@ -482,13 +482,13 @@ static void HandleFilePacket(FilePacketHdr *fp) // send a command to make a new player _local_player = 0; NetworkSendCommand(0, 0, 0, CMD_PLAYER_CTRL, NULL); - _local_player = 0xff; + _local_player = OWNER_SPECTATOR; } else { // take control over an existing company if (DEREF_PLAYER(_network_playas-1)->is_active) _local_player = _network_playas-1; else - _local_player = 0xff; + _local_player = OWNER_SPECTATOR; } } else { @@ -971,9 +971,10 @@ void NetworkListen(int port) _listensocket = ls; } -void NetworkInitialize() +void NetworkInitialize(const char *hostname) { ClientState *cs; + #if defined(WIN32) WSADATA wsa; if (WSAStartup(MAKEWORD(2,0), &wsa) != 0) @@ -993,8 +994,15 @@ void NetworkInitialize() for(cs=_clients; cs != &_clients[MAX_CLIENTS]; cs++) cs->socket = INVALID_SOCKET; - // startup udp listener - NetworkUDPListen(_network_port); + /* startup udp listener + * - only if this instance is a server, so clients can find it + * OR + * - a client, wanting to find a server to connect to + */ + if (hostname == NULL || strcmp(hostname,"auto") == 0) { + printf("Trying to open UDP port...\n"); + NetworkUDPListen(_network_port); + } } void NetworkShutdown() @@ -1168,7 +1176,7 @@ bool NetworkUDPSearchServer() { #else // ENABLE_NETWORK // stubs -void NetworkInitialize() {} +void NetworkInitialize(const char *hostname) {} void NetworkShutdown() {} void NetworkListen(int port) {} void NetworkConnect(const char *hostname, int port) {} diff --git a/network_gui.c b/network_gui.c index e6c95e655..008067e4d 100644 --- a/network_gui.c +++ b/network_gui.c @@ -26,7 +26,7 @@ void ConnectToServer(byte* b) { _networking = true; - NetworkInitialize(); + NetworkInitialize(b); DEBUG(misc, 1) ("Connecting to %s %d\n", b, _network_port); NetworkConnect(b, _network_port); } @@ -177,7 +177,7 @@ void ShowNetworkGameWindow() void StartServer() { _networking = true; - NetworkInitialize(); + NetworkInitialize(NULL); DEBUG(misc, 1) ("Listening on port %d\n", _network_port); NetworkListen(_network_port); _networking_server = true; @@ -581,7 +581,7 @@ void PlayersYearlyLoop() } } - if (_patches.show_finances && _local_player != 0xff) { + if (_patches.show_finances && _local_player != OWNER_SPECTATOR) { ShowPlayerFinances(_local_player); p = DEREF_PLAYER(_local_player); if (p->num_valid_stat_ent > 5 && p->old_economy[0].performance_history < p->old_economy[4].performance_history) { @@ -632,7 +632,7 @@ int32 CmdPlayerCtrl(int x, int y, uint32 flags, uint32 p1, uint32 p2) switch(p1 & 0xff) { case 0: // make new player p = DoStartupNewPlayer(false); - if (_local_player == 0xff && p != NULL) { + if (_local_player == OWNER_SPECTATOR && p != NULL) { _local_player = p->index; MarkWholeScreenDirty(); } diff --git a/screenshot.c b/screenshot.c index 4bf61d66a..a7b8bf655 100644 --- a/screenshot.c +++ b/screenshot.c @@ -422,7 +422,7 @@ static char *MakeScreenshotName(const char *ext) char *base; int serial; - if (_game_mode == GM_EDITOR || _local_player == 0xff) { + if (_game_mode == GM_EDITOR || _local_player == OWNER_SPECTATOR) { sprintf(_screenshot_name, "screenshot"); } else { Player *p = &_players[_local_player]; diff --git a/town_gui.c b/town_gui.c index a3ffec2d2..ca89593b8 100644 --- a/town_gui.c +++ b/town_gui.c @@ -29,7 +29,7 @@ static uint GetMaskOfTownActions(int *nump, Town *t) uint avail_buttons = 0x7F; // by default all buttons except bribe are enabled. uint buttons; - if (_local_player != 0xff) { + if (_local_player != OWNER_SPECTATOR) { // bribe option enabled? if (_patches.bribe) { // if unwanted, disable everything. @@ -489,7 +489,15 @@ int ttd_main(int argc, char* argv[]) case 'm': ttd_strlcpy(musicdriver, mgo.opt, sizeof(musicdriver)); break; case 's': ttd_strlcpy(sounddriver, mgo.opt, sizeof(sounddriver)); break; case 'v': ttd_strlcpy(videodriver, mgo.opt, sizeof(videodriver)); break; - case 'n': network=1; if (mgo.opt) {network_conn = mgo.opt; network++;} break; + case 'n': { + network = 1; + if ((bool)mgo.opt) { + network_conn = mgo.opt; + network++; + } + else + network_conn = NULL; + } break; case 'r': ParseResolution(resolution, mgo.opt); break; case 'l': { language = mgo.opt; @@ -518,7 +526,7 @@ int ttd_main(int argc, char* argv[]) break; case 'p': { int i = atoi(mgo.opt); - if (IS_INT_INSIDE(i, 0, 8)) _network_playas = i + 1; + if (IS_INT_INSIDE(i, 0, MAX_PLAYERS)) _network_playas = i + 1; break; } case -2: @@ -573,7 +581,7 @@ int ttd_main(int argc, char* argv[]) if (network) { _networking = true; - NetworkInitialize(); + NetworkInitialize(network_conn); if (network==1) { DEBUG(misc, 1) ("Listening on port %d\n", _network_port); NetworkListen(_network_port); @@ -875,7 +883,7 @@ static void DoAutosave() { char buf[200]; - if (_patches.keep_all_autosave && _local_player != 255) { + if (_patches.keep_all_autosave && _local_player != OWNER_SPECTATOR) { Player *p; char *s; sprintf(buf, "%s%s", _path.autosave_dir, PATHSEP); @@ -469,9 +469,10 @@ enum Sprites { }; enum MAP_OWNERS { - OWNER_TOWN = 0xf, // a town owns the tile - OWNER_NONE = 0x10,// nobody owns the tile - OWNER_WATER= 0x11,// "water" owns the tile + OWNER_TOWN = 0xf, // a town owns the tile + OWNER_NONE = 0x10,// nobody owns the tile + OWNER_WATER = 0x11,// "water" owns the tile + OWNER_SPECTATOR = 0xff, // spectator in MP or in scenario editor }; VARDEF bool _savegame_sort_dirty; |