Skip to content

Commit

Permalink
Revert "End Game Screen (#14)"
Browse files Browse the repository at this point in the history
This reverts commit 6e4275c.
  • Loading branch information
Zheneq committed Jan 30, 2023
1 parent be7cd30 commit bae3b3d
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 239 deletions.
19 changes: 0 additions & 19 deletions EvoS.Framework/Misc/ServerGameMetrics.cs

This file was deleted.

18 changes: 17 additions & 1 deletion EvoS.Framework/Network/Static/LobbyPlayerInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public LobbyPlayerInfo Clone()

public bool ReplacedWithBots { get; set; }

public static LobbyPlayerInfo FromServer(LobbyServerPlayerInfo serverInfo,
public static LobbyPlayerInfo FromServer(LobbyServerPlayerInfo serverInfo, int maxPlayerLevel,
MatchmakingQueueConfig queueConfig)
{
LobbyPlayerInfo lobbyPlayerInfo = null;
Expand Down Expand Up @@ -57,6 +57,22 @@ public static LobbyPlayerInfo FromServer(LobbyServerPlayerInfo serverInfo,
((!serverInfo.IsRemoteControlled) ? 0 : serverInfo.ControllingPlayerInfo.PlayerId),
EffectiveClientAccessLevel = serverInfo.EffectiveClientAccessLevel
};
if (serverInfo.AccountLevel >= maxPlayerLevel)
{
// lobbyPlayerInfo.DisplayedStat = LocalizationPayload.Create("TotalSeasonLevelStatNumber", "Global",
// new LocalizationArg[]
// {
// LocalizationArg_Int32.Create(serverInfo.TotalLevel)
// });
}
else
{
// lobbyPlayerInfo.DisplayedStat = LocalizationPayload.Create("LevelStatNumber", "Global",
// new LocalizationArg[]
// {
// LocalizationArg_Int32.Create(serverInfo.AccountLevel)
// });
}
}

return lobbyPlayerInfo;
Expand Down
5 changes: 3 additions & 2 deletions EvoS.Framework/Network/Static/LobbyTeamInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public IEnumerable<LobbyPlayerInfo> TeamInfo(Team team)
select p;
}

public static LobbyTeamInfo FromServer(LobbyServerTeamInfo serverInfo,
public static LobbyTeamInfo FromServer(LobbyServerTeamInfo serverInfo, int maxPlayerLevel,
MatchmakingQueueConfig queueConfig)
{
LobbyTeamInfo lobbyTeamInfo = null;
Expand All @@ -47,7 +47,8 @@ public static LobbyTeamInfo FromServer(LobbyServerTeamInfo serverInfo,
lobbyTeamInfo.TeamPlayerInfo = new List<LobbyPlayerInfo>();
foreach (LobbyServerPlayerInfo serverInfo2 in serverInfo.TeamPlayerInfo)
{
lobbyTeamInfo.TeamPlayerInfo.Add(LobbyPlayerInfo.FromServer(serverInfo2, queueConfig));
lobbyTeamInfo.TeamPlayerInfo.Add(LobbyPlayerInfo.FromServer(serverInfo2, maxPlayerLevel,
queueConfig));
}
}
}
Expand Down
165 changes: 21 additions & 144 deletions LobbyServer2/BridgeServer/BridgeServerProtocol.cs
Original file line number Diff line number Diff line change
@@ -1,23 +1,17 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
using CentralServer.LobbyServer;
using CentralServer.LobbyServer.Session;
using EvoS.Framework.Constants.Enums;
using EvoS.Framework.Logging;
using EvoS.Framework.Misc;
using EvoS.Framework.Network.NetworkMessages;
using EvoS.Framework.Network.Static;
using EvoS.Framework.Network.Unity;
using log4net;
using MongoDB.Bson;
using Org.BouncyCastle.Asn1.Ocsp;
using WebSocketSharp;
using WebSocketSharp.Server;
using ILog = log4net.ILog;

namespace CentralServer.BridgeServer
{
Expand Down Expand Up @@ -62,7 +56,7 @@ public IEnumerable<long> GetPlayers()
null, // typeof(MonitorHeartbeatResponse),
typeof(ServerGameSummaryNotification),
typeof(PlayerDisconnectedNotification),
typeof(ServerGameMetricsNotification),
null, // typeof(ServerGameMetricsNotification),
typeof(ServerGameStatusNotification),
null, // typeof(MonitorHeartbeatNotification),
null, // typeof(LaunchGameResponse),
Expand Down Expand Up @@ -104,70 +98,51 @@ protected override void HandleMessage(MessageEventArgs e)
ServerManager.AddServer(this);

Send(new RegisterGameServerResponse
{
Success = true
},
{
Success = true
},
callbackId);
}
else if (type == typeof(ServerGameSummaryNotification))
{
ServerGameSummaryNotification request = Deserialize<ServerGameSummaryNotification>(networkReader);

log.Debug($"< {request.GetType().Name} {DefaultJsonSerializer.Serialize(request)}");
log.Info($"Game {GameInfo.Name} finished ");

List<BadgeAndParticipantInfo> badges;
if (request.GameSummary != null)
{
log.Info($"({request.GameSummary.NumOfTurns} turns), " +
$"{request.GameSummary.GameResult} {request.GameSummary.TeamAPoints}-{request.GameSummary.TeamBPoints}");
badges = request.GameSummary.BadgeAndParticipantsInfo;
}
else
{
log.Error("Received null GameSummary. stub");
badges = new List<BadgeAndParticipantInfo>();
}

log.Info($"Game {GameInfo.Name} at {request.GameSummary.GameServerAddress} finished " +
$"({request.GameSummary.NumOfTurns} turns), " +
$"{request.GameSummary.GameResult} {request.GameSummary.TeamAPoints}-{request.GameSummary.TeamBPoints}");
foreach (LobbyServerProtocolBase client in clients)
{
MatchResultsNotification response = new MatchResultsNotification
{
BadgeAndParticipantsInfo = badges,
BaseXpGained = 100,
CurrencyRewards = new List<MatchResultsNotification.CurrencyReward>()
// TODO
BadgeAndParticipantsInfo = request.GameSummary.BadgeAndParticipantsInfo
};
client.Send(response);
}
if (request.GameSummary != null)
{
GameInfo.GameResult = request.GameSummary.GameResult;
}
else
{
// default value
GameInfo.GameResult = GameResult.TieGame;
}

UpdateGameInfoToPlayers();

Send(new ShutdownGameRequest());
}
else if (type == typeof(PlayerDisconnectedNotification))
{
PlayerDisconnectedNotification request = Deserialize<PlayerDisconnectedNotification>(networkReader);
log.Debug($"< {request.GetType().Name} {DefaultJsonSerializer.Serialize(request)}");
log.Info($"Player {request.PlayerInfo.AccountId} left game {GameInfo.GameServerProcessCode}");

OnPlayerDisconnected(request.PlayerInfo.AccountId);

foreach (LobbyServerProtocol client in clients)
{
if (client.AccountId == request.PlayerInfo.AccountId)
{
client.CurrentServer = null;
break;
}
}
}
else if (type == typeof(ServerGameStatusNotification))
{
ServerGameStatusNotification request = Deserialize<ServerGameStatusNotification>(networkReader);
log.Debug($"< {request.GetType().Name} {DefaultJsonSerializer.Serialize(request)}");
log.Info($"Game {GameInfo.Name} {request.GameStatus}");

UpdateGameStatus(request.GameStatus, true);

GameStatus = request.GameStatus;
if (GameStatus == GameStatus.Stopped)
{
foreach (LobbyServerProtocol client in clients)
Expand All @@ -176,14 +151,6 @@ protected override void HandleMessage(MessageEventArgs e)
}
}
}
else if (type == typeof(ServerGameMetricsNotification))
{
ServerGameMetricsNotification request = Deserialize<ServerGameMetricsNotification>(networkReader);
if (request.GameMetrics != null)
{
log.Debug($"Game {GameInfo.Name} is on turn {request.GameMetrics.CurrentTurn} with score {request.GameMetrics.TeamAPoints}/{request.GameMetrics.TeamBPoints}");
}
}
else
{
log.Warn($"Received unhandled bridge message type {(type != null ? type.Name : "id_" + messageType)}");
Expand Down Expand Up @@ -275,95 +242,5 @@ public short GetMessageType(AllianceMessageBase msg)

return num;
}

public void UpdateGameStatus(GameStatus status, bool notify = false)
{
// Update GameInfo's GameStatus
GameStatus = status;
GameInfo.GameStatus = status;

// If status is not None, notify players of the change
if (status == GameStatus.None || !notify) return;
GameStatusNotification notification = new GameStatusNotification() { GameStatus = status};

foreach (long player in GetPlayers())
{
LobbyServerProtocol playerConnection = SessionManager.GetClientConnection(player);
if (playerConnection != null)
{
playerConnection.Send(notification);
}
}
}

public void UpdateGameInfoToPlayers()
{
foreach(long player in GetPlayers())
{
GameInfoNotification notification = new GameInfoNotification()
{
GameInfo = this.GameInfo,
TeamInfo = LobbyTeamInfo.FromServer(this.TeamInfo, new MatchmakingQueueConfig()),
PlayerInfo = LobbyPlayerInfo.FromServer(SessionManager.GetPlayerInfo(player), new MatchmakingQueueConfig())
};
LobbyServerProtocol playerConnection = SessionManager.GetClientConnection(player);
if (playerConnection != null)
{
playerConnection.Send(notification);
}
}
}

public void OnPlayerUsedGGPack(long accountId)
{
int ggPackUsedAccountIDs = 0;
GameInfo.ggPackUsedAccountIDs.TryGetValue(accountId, out ggPackUsedAccountIDs);
GameInfo.ggPackUsedAccountIDs[accountId] = ggPackUsedAccountIDs + 1;

UpdateGameInfoToPlayers();
}

public void OnPlayerDisconnected(long accountId)
{
LobbyServerProtocol clientToRemove = null;

foreach (LobbyServerProtocol client in clients)
{
if (client.AccountId == accountId)
{
client.CurrentServer = null;
clientToRemove = client;
break;
}
}

if (clientToRemove != null)
{
clients.Remove(clientToRemove);
clientToRemove.CurrentServer = null;

GameStatusNotification notify = new GameStatusNotification()
{
GameServerProcessCode = ProcessCode,
GameStatus = GameStatus.Stopped // TODO check if there is a better way to make client leave mid-game
};

/*
* TODO: This seems to disconnect the player from the server
2019-04-29 17:52:13.373+03:00 [INF] Received Game Assignment Notification (assigned=True assigning=False reassigning=False)
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]
*/
clientToRemove.Send(notify);
}


if (clients.Count == 0)
{
log.Info("No more players in game server. Sending shutdown request");
Send(new ShutdownGameRequest());
}
}


}
}

This file was deleted.

13 changes: 9 additions & 4 deletions LobbyServer2/LobbyServer/LobbyServerProtocol.cs
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ public void HandlePlayerInfoUpdateRequest(PlayerInfoUpdateRequest request)

PlayerInfoUpdateResponse response = new PlayerInfoUpdateResponse()
{
PlayerInfo = LobbyPlayerInfo.FromServer(playerInfo, new MatchmakingQueueConfig()),
PlayerInfo = LobbyPlayerInfo.FromServer(playerInfo, 0, new MatchmakingQueueConfig()),
CharacterInfo = playerInfo.CharacterInfo,
OriginalPlayerInfoUpdate = update,
ResponseId = request.RequestId
Expand Down Expand Up @@ -408,7 +408,14 @@ public void HandleLeaveGameRequest(LeaveGameRequest request)

if (CurrentServer != null)
{
CurrentServer.OnPlayerDisconnected(AccountId);
CurrentServer.clients.Remove(this);
GameStatusNotification notify = new GameStatusNotification()
{
GameServerProcessCode = CurrentServer.ProcessCode,
GameStatus = GameStatus.Stopped // TODO check if there is a better way to make client leave mid-game
};
Send(notify);
CurrentServer = null; // we will probably want to save it somewhere for reconnection
}
}

Expand Down Expand Up @@ -772,8 +779,6 @@ public void HandleUseGGPackRequest(UseGGPackRequest request)
client.Send(useGGPackNotification);
}
}

CurrentServer.OnPlayerUsedGGPack(AccountId);
}
}

Expand Down
Loading

0 comments on commit bae3b3d

Please sign in to comment.