(svn r2) -Fix [993829] UDP Fixes (lucaspiller)

-Fix change 255/0xFF to OWNER_SPECTATOR for 
spectator stuff (TrueLight)
This commit is contained in:
darkvater 2004-08-10 14:14:00 +00:00
parent efaeb275f7
commit 804f038594
9 changed files with 41 additions and 24 deletions

View File

@ -126,7 +126,7 @@ void NetworkReceive();
void NetworkSend(); void NetworkSend();
void NetworkProcessCommands(); void NetworkProcessCommands();
void NetworkListen(int port); void NetworkListen(int port);
void NetworkInitialize(); void NetworkInitialize(const char *hostname);
void NetworkShutdown(); void NetworkShutdown();
void NetworkSendCommand(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, CommandCallback *callback); void NetworkSendCommand(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, CommandCallback *callback);
void NetworkStartSync(); void NetworkStartSync();

View File

@ -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 = AllocateWindow(x, 0x16, 0xF1, 0x52, PlayerMenuWndProc, WC_TOOLBAR_MENU, _player_menu_widgets);
w->flags4 &= ~WF_WHITE_BORDER_MASK; w->flags4 &= ~WF_WHITE_BORDER_MASK;
WP(w,menu_d).item_count = 0; 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).action_id = main_button;
WP(w,menu_d).main_button = main_button; WP(w,menu_d).main_button = main_button;
WP(w,menu_d).checked_items = gray; 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); GfxFillRect(0, 0, w->width-1, w->height-1, 0x80B4);
// if spectator, disable things // 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); w->disabled_state |= (1 << 0) | (1 << 19) | (1<<20) | (1<<21) | (1<<22) | (1<<23);
} else { } else {
w->disabled_state &= ~((1 << 0) | (1 << 19) | (1<<20) | (1<<21) | (1<<22) | (1<<23)); 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); SET_DPARAM16(0, _date);
DrawStringCentered(70, 1, ((_pause||_patches.status_long_date)?STR_00AF:STR_00AE), 0); 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) { if (p) {
// Draw player money // Draw player money
@ -1996,7 +1996,7 @@ void StatusBarWndProc(Window *w, WindowEvent *e)
if (e->click.widget == 1) { if (e->click.widget == 1) {
ShowLastNewsMessage(); ShowLastNewsMessage();
} else if (e->click.widget == 2) { } else if (e->click.widget == 2) {
if (_local_player != 0xff) ShowPlayerFinances(_local_player); if (_local_player != OWNER_SPECTATOR) ShowPlayerFinances(_local_player);
} else { } else {
ResetObjectToPlace(); ResetObjectToPlace();
} }

View File

@ -482,13 +482,13 @@ static void HandleFilePacket(FilePacketHdr *fp)
// send a command to make a new player // send a command to make a new player
_local_player = 0; _local_player = 0;
NetworkSendCommand(0, 0, 0, CMD_PLAYER_CTRL, NULL); NetworkSendCommand(0, 0, 0, CMD_PLAYER_CTRL, NULL);
_local_player = 0xff; _local_player = OWNER_SPECTATOR;
} else { } else {
// take control over an existing company // take control over an existing company
if (DEREF_PLAYER(_network_playas-1)->is_active) if (DEREF_PLAYER(_network_playas-1)->is_active)
_local_player = _network_playas-1; _local_player = _network_playas-1;
else else
_local_player = 0xff; _local_player = OWNER_SPECTATOR;
} }
} else { } else {
@ -971,9 +971,10 @@ void NetworkListen(int port)
_listensocket = ls; _listensocket = ls;
} }
void NetworkInitialize() void NetworkInitialize(const char *hostname)
{ {
ClientState *cs; ClientState *cs;
#if defined(WIN32) #if defined(WIN32)
WSADATA wsa; WSADATA wsa;
if (WSAStartup(MAKEWORD(2,0), &wsa) != 0) if (WSAStartup(MAKEWORD(2,0), &wsa) != 0)
@ -993,8 +994,15 @@ void NetworkInitialize()
for(cs=_clients; cs != &_clients[MAX_CLIENTS]; cs++) for(cs=_clients; cs != &_clients[MAX_CLIENTS]; cs++)
cs->socket = INVALID_SOCKET; cs->socket = INVALID_SOCKET;
// startup udp listener /* startup udp listener
NetworkUDPListen(_network_port); * - 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() void NetworkShutdown()
@ -1168,7 +1176,7 @@ bool NetworkUDPSearchServer() {
#else // ENABLE_NETWORK #else // ENABLE_NETWORK
// stubs // stubs
void NetworkInitialize() {} void NetworkInitialize(const char *hostname) {}
void NetworkShutdown() {} void NetworkShutdown() {}
void NetworkListen(int port) {} void NetworkListen(int port) {}
void NetworkConnect(const char *hostname, int port) {} void NetworkConnect(const char *hostname, int port) {}

View File

@ -26,7 +26,7 @@ void ConnectToServer(byte* b)
{ {
_networking = true; _networking = true;
NetworkInitialize(); NetworkInitialize(b);
DEBUG(misc, 1) ("Connecting to %s %d\n", b, _network_port); DEBUG(misc, 1) ("Connecting to %s %d\n", b, _network_port);
NetworkConnect(b, _network_port); NetworkConnect(b, _network_port);
} }
@ -177,7 +177,7 @@ void ShowNetworkGameWindow()
void StartServer() void StartServer()
{ {
_networking = true; _networking = true;
NetworkInitialize(); NetworkInitialize(NULL);
DEBUG(misc, 1) ("Listening on port %d\n", _network_port); DEBUG(misc, 1) ("Listening on port %d\n", _network_port);
NetworkListen(_network_port); NetworkListen(_network_port);
_networking_server = true; _networking_server = true;

View File

@ -581,7 +581,7 @@ void PlayersYearlyLoop()
} }
} }
if (_patches.show_finances && _local_player != 0xff) { if (_patches.show_finances && _local_player != OWNER_SPECTATOR) {
ShowPlayerFinances(_local_player); ShowPlayerFinances(_local_player);
p = DEREF_PLAYER(_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) { 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) { switch(p1 & 0xff) {
case 0: // make new player case 0: // make new player
p = DoStartupNewPlayer(false); p = DoStartupNewPlayer(false);
if (_local_player == 0xff && p != NULL) { if (_local_player == OWNER_SPECTATOR && p != NULL) {
_local_player = p->index; _local_player = p->index;
MarkWholeScreenDirty(); MarkWholeScreenDirty();
} }

View File

@ -422,7 +422,7 @@ static char *MakeScreenshotName(const char *ext)
char *base; char *base;
int serial; int serial;
if (_game_mode == GM_EDITOR || _local_player == 0xff) { if (_game_mode == GM_EDITOR || _local_player == OWNER_SPECTATOR) {
sprintf(_screenshot_name, "screenshot"); sprintf(_screenshot_name, "screenshot");
} else { } else {
Player *p = &_players[_local_player]; Player *p = &_players[_local_player];

View File

@ -29,7 +29,7 @@ static uint GetMaskOfTownActions(int *nump, Town *t)
uint avail_buttons = 0x7F; // by default all buttons except bribe are enabled. uint avail_buttons = 0x7F; // by default all buttons except bribe are enabled.
uint buttons; uint buttons;
if (_local_player != 0xff) { if (_local_player != OWNER_SPECTATOR) {
// bribe option enabled? // bribe option enabled?
if (_patches.bribe) { if (_patches.bribe) {
// if unwanted, disable everything. // if unwanted, disable everything.

16
ttd.c
View File

@ -489,7 +489,15 @@ int ttd_main(int argc, char* argv[])
case 'm': ttd_strlcpy(musicdriver, mgo.opt, sizeof(musicdriver)); break; case 'm': ttd_strlcpy(musicdriver, mgo.opt, sizeof(musicdriver)); break;
case 's': ttd_strlcpy(sounddriver, mgo.opt, sizeof(sounddriver)); break; case 's': ttd_strlcpy(sounddriver, mgo.opt, sizeof(sounddriver)); break;
case 'v': ttd_strlcpy(videodriver, mgo.opt, sizeof(videodriver)); 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 'r': ParseResolution(resolution, mgo.opt); break;
case 'l': { case 'l': {
language = mgo.opt; language = mgo.opt;
@ -518,7 +526,7 @@ int ttd_main(int argc, char* argv[])
break; break;
case 'p': { case 'p': {
int i = atoi(mgo.opt); 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; break;
} }
case -2: case -2:
@ -573,7 +581,7 @@ int ttd_main(int argc, char* argv[])
if (network) { if (network) {
_networking = true; _networking = true;
NetworkInitialize(); NetworkInitialize(network_conn);
if (network==1) { if (network==1) {
DEBUG(misc, 1) ("Listening on port %d\n", _network_port); DEBUG(misc, 1) ("Listening on port %d\n", _network_port);
NetworkListen(_network_port); NetworkListen(_network_port);
@ -875,7 +883,7 @@ static void DoAutosave()
{ {
char buf[200]; char buf[200];
if (_patches.keep_all_autosave && _local_player != 255) { if (_patches.keep_all_autosave && _local_player != OWNER_SPECTATOR) {
Player *p; Player *p;
char *s; char *s;
sprintf(buf, "%s%s", _path.autosave_dir, PATHSEP); sprintf(buf, "%s%s", _path.autosave_dir, PATHSEP);

7
ttd.h
View File

@ -469,9 +469,10 @@ enum Sprites {
}; };
enum MAP_OWNERS { enum MAP_OWNERS {
OWNER_TOWN = 0xf, // a town owns the tile OWNER_TOWN = 0xf, // a town owns the tile
OWNER_NONE = 0x10,// nobody owns the tile OWNER_NONE = 0x10,// nobody owns the tile
OWNER_WATER= 0x11,// "water" 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; VARDEF bool _savegame_sort_dirty;