1- using System ;
1+ using System ;
22using System . Collections . Generic ;
33using System . Linq ;
44using System . Reflection ;
5- using System . Threading ;
6- using System . Threading . Tasks ;
75using CentralServer . LobbyServer ;
86using CentralServer . LobbyServer . Session ;
97using EvoS . Framework . Constants . Enums ;
10- using EvoS . Framework . Logging ;
118using EvoS . Framework . Misc ;
129using EvoS . Framework . Network . NetworkMessages ;
1310using EvoS . Framework . Network . Static ;
1411using EvoS . Framework . Network . Unity ;
1512using log4net ;
16- using MongoDB . Bson ;
17- using Org . BouncyCastle . Asn1 . Ocsp ;
1813using WebSocketSharp ;
1914using WebSocketSharp . Server ;
20- using ILog = log4net . ILog ;
2115
2216namespace CentralServer . BridgeServer
2317{
@@ -62,7 +56,7 @@ public IEnumerable<long> GetPlayers()
6256 null , // typeof(MonitorHeartbeatResponse),
6357 typeof ( ServerGameSummaryNotification ) ,
6458 typeof ( PlayerDisconnectedNotification ) ,
65- typeof ( ServerGameMetricsNotification ) ,
59+ null , // typeof(ServerGameMetricsNotification),
6660 typeof ( ServerGameStatusNotification ) ,
6761 null , // typeof(MonitorHeartbeatNotification),
6862 null , // typeof(LaunchGameResponse),
@@ -104,70 +98,51 @@ protected override void HandleMessage(MessageEventArgs e)
10498 ServerManager . AddServer ( this ) ;
10599
106100 Send ( new RegisterGameServerResponse
107- {
108- Success = true
109- } ,
101+ {
102+ Success = true
103+ } ,
110104 callbackId ) ;
111105 }
112106 else if ( type == typeof ( ServerGameSummaryNotification ) )
113107 {
114108 ServerGameSummaryNotification request = Deserialize < ServerGameSummaryNotification > ( networkReader ) ;
115-
116109 log . Debug ( $ "< { request . GetType ( ) . Name } { DefaultJsonSerializer . Serialize ( request ) } ") ;
117- log . Info ( $ "Game { GameInfo . Name } finished ") ;
118-
119- List < BadgeAndParticipantInfo > badges ;
120- if ( request . GameSummary != null )
121- {
122- log . Info ( $ "({ request . GameSummary . NumOfTurns } turns), " +
123- $ "{ request . GameSummary . GameResult } { request . GameSummary . TeamAPoints } -{ request . GameSummary . TeamBPoints } ") ;
124- badges = request . GameSummary . BadgeAndParticipantsInfo ;
125- }
126- else
127- {
128- log . Error ( "Received null GameSummary. stub" ) ;
129- badges = new List < BadgeAndParticipantInfo > ( ) ;
130- }
131-
110+ log . Info ( $ "Game { GameInfo . Name } at { request . GameSummary . GameServerAddress } finished " +
111+ $ "({ request . GameSummary . NumOfTurns } turns), " +
112+ $ "{ request . GameSummary . GameResult } { request . GameSummary . TeamAPoints } -{ request . GameSummary . TeamBPoints } ") ;
132113 foreach ( LobbyServerProtocolBase client in clients )
133114 {
134115 MatchResultsNotification response = new MatchResultsNotification
135116 {
136- BadgeAndParticipantsInfo = badges ,
137- BaseXpGained = 100 ,
138- CurrencyRewards = new List < MatchResultsNotification . CurrencyReward > ( )
117+ // TODO
118+ BadgeAndParticipantsInfo = request . GameSummary . BadgeAndParticipantsInfo
139119 } ;
140120 client . Send ( response ) ;
141121 }
142- if ( request . GameSummary != null )
143- {
144- GameInfo . GameResult = request . GameSummary . GameResult ;
145- }
146- else
147- {
148- // default value
149- GameInfo . GameResult = GameResult . TieGame ;
150- }
151-
152- UpdateGameInfoToPlayers ( ) ;
122+
123+ Send ( new ShutdownGameRequest ( ) ) ;
153124 }
154125 else if ( type == typeof ( PlayerDisconnectedNotification ) )
155126 {
156127 PlayerDisconnectedNotification request = Deserialize < PlayerDisconnectedNotification > ( networkReader ) ;
157128 log . Debug ( $ "< { request . GetType ( ) . Name } { DefaultJsonSerializer . Serialize ( request ) } ") ;
158129 log . Info ( $ "Player { request . PlayerInfo . AccountId } left game { GameInfo . GameServerProcessCode } ") ;
159-
160- OnPlayerDisconnected ( request . PlayerInfo . AccountId ) ;
161130
131+ foreach ( LobbyServerProtocol client in clients )
132+ {
133+ if ( client . AccountId == request . PlayerInfo . AccountId )
134+ {
135+ client . CurrentServer = null ;
136+ break ;
137+ }
138+ }
162139 }
163140 else if ( type == typeof ( ServerGameStatusNotification ) )
164141 {
165142 ServerGameStatusNotification request = Deserialize < ServerGameStatusNotification > ( networkReader ) ;
166143 log . Debug ( $ "< { request . GetType ( ) . Name } { DefaultJsonSerializer . Serialize ( request ) } ") ;
167144 log . Info ( $ "Game { GameInfo . Name } { request . GameStatus } ") ;
168-
169- UpdateGameStatus ( request . GameStatus , true ) ;
170-
145+ GameStatus = request . GameStatus ;
171146 if ( GameStatus == GameStatus . Stopped )
172147 {
173148 foreach ( LobbyServerProtocol client in clients )
@@ -176,14 +151,6 @@ protected override void HandleMessage(MessageEventArgs e)
176151 }
177152 }
178153 }
179- else if ( type == typeof ( ServerGameMetricsNotification ) )
180- {
181- ServerGameMetricsNotification request = Deserialize < ServerGameMetricsNotification > ( networkReader ) ;
182- if ( request . GameMetrics != null )
183- {
184- log . Debug ( $ "Game { GameInfo . Name } is on turn { request . GameMetrics . CurrentTurn } with score { request . GameMetrics . TeamAPoints } /{ request . GameMetrics . TeamBPoints } ") ;
185- }
186- }
187154 else
188155 {
189156 log . Warn ( $ "Received unhandled bridge message type { ( type != null ? type . Name : "id_" + messageType ) } ") ;
@@ -275,95 +242,5 @@ public short GetMessageType(AllianceMessageBase msg)
275242
276243 return num ;
277244 }
278-
279- public void UpdateGameStatus ( GameStatus status , bool notify = false )
280- {
281- // Update GameInfo's GameStatus
282- GameStatus = status ;
283- GameInfo . GameStatus = status ;
284-
285- // If status is not None, notify players of the change
286- if ( status == GameStatus . None || ! notify ) return ;
287- GameStatusNotification notification = new GameStatusNotification ( ) { GameStatus = status } ;
288-
289- foreach ( long player in GetPlayers ( ) )
290- {
291- LobbyServerProtocol playerConnection = SessionManager . GetClientConnection ( player ) ;
292- if ( playerConnection != null )
293- {
294- playerConnection . Send ( notification ) ;
295- }
296- }
297- }
298-
299- public void UpdateGameInfoToPlayers ( )
300- {
301- foreach ( long player in GetPlayers ( ) )
302- {
303- GameInfoNotification notification = new GameInfoNotification ( )
304- {
305- GameInfo = this . GameInfo ,
306- TeamInfo = LobbyTeamInfo . FromServer ( this . TeamInfo , new MatchmakingQueueConfig ( ) ) ,
307- PlayerInfo = LobbyPlayerInfo . FromServer ( SessionManager . GetPlayerInfo ( player ) , new MatchmakingQueueConfig ( ) )
308- } ;
309- LobbyServerProtocol playerConnection = SessionManager . GetClientConnection ( player ) ;
310- if ( playerConnection != null )
311- {
312- playerConnection . Send ( notification ) ;
313- }
314- }
315- }
316-
317- public void OnPlayerUsedGGPack ( long accountId )
318- {
319- int ggPackUsedAccountIDs = 0 ;
320- GameInfo . ggPackUsedAccountIDs . TryGetValue ( accountId , out ggPackUsedAccountIDs ) ;
321- GameInfo . ggPackUsedAccountIDs [ accountId ] = ggPackUsedAccountIDs + 1 ;
322-
323- UpdateGameInfoToPlayers ( ) ;
324- }
325-
326- public void OnPlayerDisconnected ( long accountId )
327- {
328- LobbyServerProtocol clientToRemove = null ;
329-
330- foreach ( LobbyServerProtocol client in clients )
331- {
332- if ( client . AccountId == accountId )
333- {
334- client . CurrentServer = null ;
335- clientToRemove = client ;
336- break ;
337- }
338- }
339-
340- if ( clientToRemove != null )
341- {
342- clients . Remove ( clientToRemove ) ;
343- clientToRemove . CurrentServer = null ;
344-
345- GameStatusNotification notify = new GameStatusNotification ( )
346- {
347- GameServerProcessCode = ProcessCode ,
348- GameStatus = GameStatus . Stopped // TODO check if there is a better way to make client leave mid-game
349- } ;
350-
351- /*
352- * TODO: This seems to disconnect the player from the server
353- 2019-04-29 17:52:13.373+03:00 [INF] Received Game Assignment Notification (assigned=True assigning=False reassigning=False)
354- 2019-04-29 17:52:13.373+03:00 [INF] Unassigned from game 0a101c39-5cc7-077f (wss://208.94.25.140:6148) [RobotFactory_Deathmatch PvP GenericPvP]
355- */
356- clientToRemove . Send ( notify ) ;
357- }
358-
359-
360- if ( clients . Count == 0 )
361- {
362- log . Info ( "No more players in game server. Sending shutdown request" ) ;
363- Send ( new ShutdownGameRequest ( ) ) ;
364- }
365- }
366-
367-
368245 }
369246}
0 commit comments