Changeset - r1:d67833cf1719
[Not reviewed]
master
0 9 0
darkvater - 20 years ago 2004-08-10 14:14:00
darkvater@openttd.org
(svn r2) -Fix [993829] UDP Fixes (lucaspiller)
-Fix change 255/0xFF to OWNER_SPECTATOR for
spectator stuff (TrueLight)
9 files changed with 41 insertions and 24 deletions:
0 comments (0 inline, 0 general)
functions.h
Show inline comments
 
@@ -123,13 +123,13 @@ bool DoCommandP(TileIndex tile, uint32 p
 

	
 
void NetworkConnect(const char *hostname, int port);
 
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();
 
void NetworkUDPListen(int port);
 
void NetworkUDPReceive();
 
void NetworkIPListInit();
main_gui.c
Show inline comments
 
@@ -594,13 +594,13 @@ static Window *PopupMainPlayerToolbMenu(
 
	InvalidateWidget(w, main_button);
 

	
 
	DeleteWindowById(WC_TOOLBAR_MENU, 0);
 
	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;
 
	_popup_menu_active = true;
 
	SndPlayFx(0x13);
 
	return w;
 
@@ -1630,13 +1630,13 @@ static void MainToolbarWndProc(Window *w
 

	
 
		// Draw brown-red toolbar bg.
 
		GfxFillRect(0, 0, w->width-1, w->height-1, 0xB2);
 
		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));
 
		}
 

	
 
		DrawWindowWidgets(w);
 
@@ -1962,13 +1962,13 @@ void StatusBarWndProc(Window *w, WindowE
 
	switch(e->event) {
 
	case WE_PAINT:
 
		DrawWindowWidgets(w);
 
		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
 
			SET_DPARAM64(0, p->money64);
 
			DrawStringCentered(570, 1, p->player_money >= 0 ? STR_0004 : STR_0005, 0);
 
		}
 
@@ -1993,13 +1993,13 @@ void StatusBarWndProc(Window *w, WindowE
 
		break;
 

	
 
	case WE_CLICK:
 
		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();
 
		}
 
		break;
 

	
 
	case WE_TICK: {
network.c
Show inline comments
 
@@ -479,19 +479,19 @@ static void HandleFilePacket(FilePacketH
 
		memset(_my_seed_list, 0, sizeof(_my_seed_list));
 

	
 
		if (_network_playas == 0) {
 
			// 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 {
 
		if(!_recv_file) {
 
			_recv_file = fopen("networkc.tmp", "wb");
 
			if (!_recv_file) error("can't open savefile");
 
@@ -968,15 +968,16 @@ void NetworkListen(int port)
 
	if (listen(ls, 1) != 0)
 
		error("listen() failed");
 

	
 
	_listensocket = ls;
 
}
 

	
 
void NetworkInitialize()
 
void NetworkInitialize(const char *hostname)
 
{
 
	ClientState *cs;
 

	
 
#if defined(WIN32)
 
	WSADATA wsa;
 
	if (WSAStartup(MAKEWORD(2,0), &wsa) != 0)
 
		error("WSAStartup failed");
 
#endif
 

	
 
@@ -990,14 +991,21 @@ void NetworkInitialize()
 
	_ack_queue.last = &_ack_queue.head;
 

	
 
	// invalidate all clients
 
	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()
 
{
 
#if defined(__MORPHOS__) || defined(__AMIGA__)
 
	if (SocketBase) {
 
@@ -1165,13 +1173,13 @@ 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) {}
 
void NetworkReceive() {}
 
void NetworkSend() {}
 
void NetworkSendCommand(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, CommandCallback *callback) {}
network_gui.c
Show inline comments
 
@@ -23,13 +23,13 @@ char *direct_ip = NULL;
 

	
 

	
 
void ConnectToServer(byte* b)
 
{
 
	_networking = true;
 
	
 
	NetworkInitialize();
 
	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,
 
@@ -174,13 +174,13 @@ 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;
 
	DoCommandP(0, 0, 0, NULL, CMD_START_NEW_GAME);
 
}
 

	
players.c
Show inline comments
 
@@ -578,13 +578,13 @@ void PlayersYearlyLoop()
 
			memmove(&p->yearly_expenses[1], &p->yearly_expenses[0], sizeof(p->yearly_expenses) - sizeof(p->yearly_expenses[0]));
 
			memset(&p->yearly_expenses[0], 0, sizeof(p->yearly_expenses[0]));
 
			InvalidateWindow(WC_FINANCES, p->index);
 
		}
 
	}
 

	
 
	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) {
 
			SndPlayFx(0x28);
 
		} else {
 
			SndPlayFx(0x27);
 
@@ -629,13 +629,13 @@ int32 CmdPlayerCtrl(int x, int y, uint32
 
	if (!(flags & DC_EXEC))
 
		return 0;
 
	
 
	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();
 
		}
 
		break;
 
	case 1: // make new ai player
 
		DoStartupNewPlayer(true);
screenshot.c
Show inline comments
 
@@ -419,13 +419,13 @@ void LargeWorldCallback(void *userdata, 
 
static char *MakeScreenshotName(const char *ext)
 
{
 
	static char filename[256];
 
	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];
 
		SET_DPARAM16(0, p->name_1);
 
		SET_DPARAM32(1, p->name_2);
 
		SET_DPARAM16(2, _date);
town_gui.c
Show inline comments
 
@@ -26,13 +26,13 @@ static uint GetMaskOfTownActions(int *nu
 
{
 
	int32 avail, ref;
 
	int i, num;
 
	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.
 
			if (t->unwanted[_local_player]) {
 
				avail_buttons = 0;
 
			} else if (t->ratings[_local_player] < 600)
ttd.c
Show inline comments
 
@@ -486,13 +486,21 @@ int ttd_main(int argc, char* argv[])
 
	MyGetOptInit(&mgo, argc-1, argv+1, "m:s:v:hn::l:eit:d::r:g::G:cp:");
 
	while ((i = MyGetOpt(&mgo)) != -1) {
 
		switch(i) {
 
		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;
 
			} break;
 
		case 't': {
 
				startdate = atoi(mgo.opt);
 
@@ -515,13 +523,13 @@ int ttd_main(int argc, char* argv[])
 
			break;
 
		case 'G':
 
			_random_seed_1 = atoi(mgo.opt);
 
			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:
 
 		case 'h':
 
			showhelp();
 
			return 0;
 
@@ -570,13 +578,13 @@ int ttd_main(int argc, char* argv[])
 
	if (_opt_mod_ptr->diff_level == 9)
 
		SetDifficultyLevel(0, _opt_mod_ptr);
 

	
 
	if (network) {
 
		_networking = true;
 
		
 
		NetworkInitialize();
 
		NetworkInitialize(network_conn);
 
		if (network==1) {
 
			DEBUG(misc, 1) ("Listening on port %d\n", _network_port);
 
			NetworkListen(_network_port);
 
			_networking_server = true;
 
		} else {
 
			DEBUG(misc, 1) ("Connecting to %s %d\n", network_conn, _network_port);
 
@@ -872,13 +880,13 @@ void StateGameLoop()
 
}
 

	
 
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);
 
		p = DEREF_PLAYER(_local_player);
 
		SET_DPARAM16(0, p->name_1);
 
		SET_DPARAM32(1, p->name_2);
ttd.h
Show inline comments
 
@@ -466,15 +466,16 @@ typedef void PlaceProc(uint tile);
 
enum Sprites {
 
	SPR_OPENTTD_BASE = 0x1406,
 
	SPR_CANALS_BASE = SPR_OPENTTD_BASE + 80,
 
};
 

	
 
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;
 
VARDEF byte _savegame_sort_order;
 

	
 
#define INVALID_UINT_TILE (uint)0xFFFFFFFF
0 comments (0 inline, 0 general)