bandaid for invalid master client id being sent by server

upm
Anton Franzluebbers 2022-04-01 14:37:08 -04:00
parent 36f16b35df
commit eeb539ba49
1 changed files with 11 additions and 3 deletions

View File

@ -472,8 +472,16 @@ namespace VelNet
case ChangeMasterMessage cm: case ChangeMasterMessage cm:
{ {
if (masterPlayer == null) if (masterPlayer == null)
{
if (players.ContainsKey(cm.masterId))
{ {
masterPlayer = players[cm.masterId]; masterPlayer = players[cm.masterId];
}
else
{
masterPlayer = players.Aggregate((p1, p2) => p1.Value.userid.CompareTo(p2.Value.userid) > 0 ? p1 : p2).Value;
Debug.LogError("Got an invalid master client id from the server. Using fallback.");
}
// no master player yet, add the scene objects // no master player yet, add the scene objects
@ -755,11 +763,11 @@ namespace VelNet
AddMessage(m); AddMessage(m);
break; break;
} }
//new master // new master
case MessageReceivedType.MASTER_MESSAGE: case MessageReceivedType.MASTER_MESSAGE:
{ {
ChangeMasterMessage m = new ChangeMasterMessage(); ChangeMasterMessage m = new ChangeMasterMessage();
m.masterId = GetIntFromBytes(ReadExact(stream, 4)); //sender is the new master m.masterId = GetIntFromBytes(ReadExact(stream, 4)); // sender is the new master
AddMessage(m); AddMessage(m);
break; break;
} }