PageRenderTime 26ms CodeModel.GetById 17ms app.highlight 3ms RepoModel.GetById 2ms app.codeStats 0ms

/ggb_v1.0_src/ggb_ghost_patch.patch

http://ghostcb.googlecode.com/
Patch | 166 lines | 156 code | 10 blank | 0 comment | 0 complexity | ce04bcc748f9b64c454b16785d94bde3 MD5 | raw file
  1Index: ghost/game_base.cpp
  2===================================================================
  3--- ghost/game_base.cpp	(revision 536)
  4+++ ghost/game_base.cpp	(working copy)
  5@@ -458,6 +458,7 @@
  6 		// see the !sendlan code later in this file for some more information about how this works
  7 		// todotodo: should we send a game cancel message somewhere? we'll need to implement a host counter for it to work
  8 
  9+
 10 		if( !m_CountDownStarted )
 11 		{
 12 			// construct a fixed host counter which will be used to identify players from this "realm" (i.e. LAN)
 13@@ -475,23 +476,59 @@
 14 
 15 				uint32_t MapGameType = MAPGAMETYPE_SAVEDGAME;
 16 				BYTEARRAY MapWidth;
 17-				MapWidth.push_back( 0 );
 18-				MapWidth.push_back( 0 );
 19 				BYTEARRAY MapHeight;
 20-				MapHeight.push_back( 0 );
 21-				MapHeight.push_back( 0 );
 22-				m_GHost->m_UDPSocket->Broadcast( 6112, m_Protocol->SEND_W3GS_GAMEINFO( m_GHost->m_TFT, m_GHost->m_LANWar3Version, UTIL_CreateByteArray( MapGameType, false ), m_Map->GetMapGameFlags( ), MapWidth, MapHeight, m_GameName, "Varlock", GetTime( ) - m_CreationTime, "Save\\Multiplayer\\" + m_SaveGame->GetFileNameNoPath( ), m_SaveGame->GetMagicNumber( ), 12, 12, m_HostPort, FixedHostCounter ) );
 23+				if ( m_GHost->m_Reconnect )
 24+				{
 25+					MapWidth.push_back( 192 );
 26+					MapWidth.push_back( 7 );
 27+
 28+					MapHeight.push_back( 192 );
 29+					MapHeight.push_back( 7 );
 30+				}
 31+				else
 32+				{
 33+					MapWidth.push_back( 0 );
 34+					MapWidth.push_back( 0 );
 35+
 36+					MapHeight.push_back( 0 );
 37+					MapHeight.push_back( 0 );
 38+				}
 39+
 40+				BYTEARRAY data = m_Protocol->SEND_W3GS_GAMEINFO( m_GHost->m_TFT, m_GHost->m_LANWar3Version, UTIL_CreateByteArray( MapGameType, false ), m_Map->GetMapGameFlags( ), MapWidth, MapHeight, m_GameName, "Varlock", GetTime( ) - m_CreationTime, "Save\\Multiplayer\\" + m_SaveGame->GetFileNameNoPath( ), m_SaveGame->GetMagicNumber( ), 12, 12, m_HostPort, FixedHostCounter );
 41+				m_GHost->m_UDPSocket->Broadcast( 6112, data );
 42+				for(vector<CTCPSocket * >::iterator i = m_GHost->m_GameBroadcasters.begin( ); i!= m_GHost->m_GameBroadcasters.end( ); i++ )
 43+				{
 44+					(*i)->PutBytes( data );
 45+				}
 46 			}
 47 			else
 48 			{
 49 				// note: the PrivateGame flag is not set when broadcasting to LAN (as you might expect)
 50 				// note: we do not use m_Map->GetMapGameType because none of the filters are set when broadcasting to LAN (also as you might expect)
 51+				uint32_t MapGameType = MAPGAMETYPE_UNKNOWN0;
 52+				BYTEARRAY MapWidth;
 53+				BYTEARRAY MapHeight;
 54+				if ( m_GHost->m_Reconnect )
 55+				{
 56+					MapWidth.push_back( 192 );
 57+					MapWidth.push_back( 7 );
 58 
 59-				uint32_t MapGameType = MAPGAMETYPE_UNKNOWN0;
 60-				m_GHost->m_UDPSocket->Broadcast( 6112, m_Protocol->SEND_W3GS_GAMEINFO( m_GHost->m_TFT, m_GHost->m_LANWar3Version, UTIL_CreateByteArray( MapGameType, false ), m_Map->GetMapGameFlags( ), m_Map->GetMapWidth( ), m_Map->GetMapHeight( ), m_GameName, "Varlock", GetTime( ) - m_CreationTime, m_Map->GetMapPath( ), m_Map->GetMapCRC( ), 12, 12, m_HostPort, FixedHostCounter ) );
 61+					MapHeight.push_back( 192 );
 62+					MapHeight.push_back( 7 );
 63+				}
 64+				else
 65+				{
 66+					MapWidth = m_Map->GetMapWidth( );
 67+					MapHeight = m_Map->GetMapHeight( );
 68+				}
 69+				BYTEARRAY data = m_Protocol->SEND_W3GS_GAMEINFO( m_GHost->m_TFT, m_GHost->m_LANWar3Version, UTIL_CreateByteArray( MapGameType, false ), m_Map->GetMapGameFlags( ), MapWidth, MapHeight, m_GameName, "Varlock", GetTime( ) - m_CreationTime, m_Map->GetMapPath( ), m_Map->GetMapCRC( ), 12, 12, m_HostPort, FixedHostCounter );
 70+				m_GHost->m_UDPSocket->Broadcast( 6112, data );
 71+				for(vector<CTCPSocket * >::iterator i = m_GHost->m_GameBroadcasters.begin( ); i!= m_GHost->m_GameBroadcasters.end( ); i++ )
 72+				{
 73+					(*i)->PutBytes( data );
 74+				}
 75 			}
 76 		}
 77-
 78 		m_LastPingTime = GetTime( );
 79 	}
 80 
 81Index: ghost/ghost.cpp
 82===================================================================
 83--- ghost/ghost.cpp	(revision 536)
 84+++ ghost/ghost.cpp	(working copy)
 85@@ -678,6 +678,14 @@
 86 	else
 87 		m_AdminGame = NULL;
 88 
 89+		// create the listening socket for broadcasters;
 90+	
 91+	int Port = CFG->GetInt("bot_broadcasters_port", 6969 );
 92+	m_GameBroadcastersListener = new CTCPServer( );
 93+	m_GameBroadcastersListener->Listen( string( ),Port );
 94+	CONSOLE_Print( "[GHOST] Listening for game broadcasters on port [" + UTIL_ToString( Port ) +"]" );
 95+
 96+
 97 	if( m_BNETs.empty( ) && !m_AdminGame )
 98 		CONSOLE_Print( "[GHOST] warning - no battle.net connections found and no admin game created" );
 99 
100@@ -880,7 +888,21 @@
101 		(*i)->SetFD( &fd, &send_fd, &nfds );
102 		NumFDs++;
103 	}
104+	// 6. the Game Broadcasters
105+	for(vector<CTCPSocket * >::iterator i = m_GameBroadcasters.begin( ); i!= m_GameBroadcasters.end( ); i++ )
106+	{
107+		if ( (*i)->GetConnected( ) && !(*i)->HasError( ) )
108+		{
109+			(*i)->SetFD( &fd, &send_fd, &nfds );
110+			NumFDs++;
111+		}
112+	}
113 
114+	// 7. the listener for game broadcasters
115+	m_GameBroadcastersListener->SetFD( &fd, &send_fd,&nfds );
116+	NumFDs++;
117+
118+
119 	// before we call select we need to determine how long to block for
120 	// previously we just blocked for a maximum of the passed usecBlock microseconds
121 	// however, in an effort to make game updates happen closer to the desired latency setting we now use a dynamic block interval
122@@ -1171,6 +1193,31 @@
123 		m_LastAutoHostTime = GetTime( );
124 	}
125 
126+	CTCPSocket *NewSocket = m_GameBroadcastersListener->Accept( &fd );
127+	if ( NewSocket )
128+	{
129+		m_GameBroadcasters.push_back( NewSocket );
130+		CONSOLE_Print("[GHOST] Game Broadcaster [" + NewSocket->GetIPString( ) +"] connected" );
131+		//BYTEARRAY info;
132+	 //   UTIL_AppendByteArray( info, m_AdminGamePort,false );
133+		//UTIL_AppendByteArray( info, m_HostPort, false );
134+		//NewSocket->PutBytes( info );
135+	}
136+	for(vector<CTCPSocket * >::iterator i = m_GameBroadcasters.begin( ); i!= m_GameBroadcasters.end( ); )
137+	{
138+		if ( (*i)->HasError( ) || !(*i)->GetConnected( ) )
139+		{
140+			CONSOLE_Print("[GHOST] Game Broadcaster [" + (*i)->GetIPString( ) +"] disconnected");
141+			delete *i;
142+			i = m_GameBroadcasters.erase( i );
143+			continue;
144+		}
145+		//(*i)->DoRecv( &fd );
146+		(*i)->DoSend( &send_fd );
147+		i++;
148+	}
149+
150+
151 	return m_Exiting || AdminExit || BNETExit;
152 }
153 
154Index: ghost/ghost.h
155===================================================================
156--- ghost/ghost.h	(revision 536)
157+++ ghost/ghost.h	(working copy)
158@@ -133,6 +133,8 @@
159 	uint32_t m_ReplayBuildNumber;			// config value: replay build number (for saving replays)
160 	bool m_TCPNoDelay;						// config value: use Nagle's algorithm or not
161 	uint32_t m_MatchMakingMethod;			// config value: the matchmaking method
162+	CTCPServer *m_GameBroadcastersListener; // listening socket for game broadcasters
163+	vector<CTCPSocket *> m_GameBroadcasters;// vector of sockets that broadcast the games
164 
165 	CGHost( CConfig *CFG );
166 	~CGHost( );