From 00cfa93034c5b6fad750b395ac14a1c58c9dd93f Mon Sep 17 00:00:00 2001 From: chai Date: Mon, 4 Jan 2021 14:52:20 +0800 Subject: =?UTF-8?q?*=E5=8D=8F=E8=AE=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Client/Assembly-CSharp/InnerNet/InnerNetClient.cs | 316 +++++++++++----------- 1 file changed, 161 insertions(+), 155 deletions(-) (limited to 'Client/Assembly-CSharp/InnerNet/InnerNetClient.cs') diff --git a/Client/Assembly-CSharp/InnerNet/InnerNetClient.cs b/Client/Assembly-CSharp/InnerNet/InnerNetClient.cs index 5806605..30121eb 100644 --- a/Client/Assembly-CSharp/InnerNet/InnerNetClient.cs +++ b/Client/Assembly-CSharp/InnerNet/InnerNetClient.cs @@ -588,6 +588,7 @@ namespace InnerNet } // 加入游戏 + // MsgWrite:JoinGame public void JoinGame() { this.ClientId = -1; @@ -617,7 +618,7 @@ namespace InnerNet return this.IsGameStarted || this.AmHost; } - // 踢玩家 + // 踢玩家 MsgWrite:KickPlayer public void KickPlayer(int clientId, bool ban) { if (!this.AmHost) @@ -651,6 +652,7 @@ namespace InnerNet msg.Recycle(); } + // MsgWrite:RemovePlayer , 移除玩家 protected void SendLateRejection(int targetId, DisconnectReasons reason) { MessageWriter messageWriter = MessageWriter.Get(SendOption.Reliable); @@ -688,6 +690,7 @@ namespace InnerNet clientData.IsReady = true; } + // MsgWrite:StartGame protected void SendStartGame() { MessageWriter messageWriter = MessageWriter.Get(SendOption.Reliable); @@ -698,17 +701,19 @@ namespace InnerNet messageWriter.Recycle(); } + // MsgWrite:GetGameList , 获得游戏房间列表 public void RequestGameList(bool includePrivate, IBytesSerializable settings) { MessageWriter messageWriter = MessageWriter.Get(SendOption.Reliable); - messageWriter.StartMessage(9); - messageWriter.Write(includePrivate); + messageWriter.StartMessage(9); // GetGameList + messageWriter.Write(includePrivate); messageWriter.WriteBytesAndSize(settings.ToBytes()); messageWriter.EndMessage(); this.SendOrDisconnect(messageWriter); messageWriter.Recycle(); } + // MsgWrite:AlterGame , 切换房间的public和private public void ChangeGamePublic(bool isPublic) { if (this.AmHost) @@ -796,20 +801,65 @@ namespace InnerNet return; } break; - case 1: - goto IL_2F5; - case (int)TagAlias.StartGame: - this.GameState = InnerNetClient.GameStates.Started; - obj = this.Dispatcher; - lock (obj) + case Tags.JoinGame: //MsgRead:JoinGame + goto IL_2F5; + IL_2F5: + int num8 = reader.ReadInt32(); // 如果加入失败,gameId存失败原因 + DisconnectReasons disconnectReasons = (DisconnectReasons)num8; + if (InnerNetClient.disconnectReasons.Contains(disconnectReasons)) + { + if (disconnectReasons == DisconnectReasons.Custom) + { + this.LastCustomDisconnect = reader.ReadString(); + } + this.GameId = -1; + this.EnqueueDisconnect(disconnectReasons, null); + return; + } + if (this.GameId == num8) + { + int num9 = reader.ReadInt32(); + bool amHost = this.AmHost; + this.HostId = reader.ReadInt32(); + ClientData client = this.GetOrCreateClient(num9); + Debug.Log(string.Format("Player {0} joined", num9)); + obj = this.Dispatcher; + lock (obj) + { + this.Dispatcher.Add(delegate + { + // 某个玩家加入了本局 + this.OnPlayerJoined(client); + }); + } + if (!this.AmHost || amHost) + { + return; + } + obj = this.Dispatcher; + lock (obj) + { + this.Dispatcher.Add(delegate + { + this.OnBecomeHost(); + }); + return; + } + } + this.EnqueueDisconnect(DisconnectReasons.IncorrectGame, null); + return; + case Tags.StartGame: // MsgRead:StartGame + this.GameState = InnerNetClient.GameStates.Started; + obj = this.Dispatcher; + lock (obj) + { + this.Dispatcher.Add(delegate { - this.Dispatcher.Add(delegate - { - this.OnStartGame(); - }); - return; - } - goto IL_675; + this.OnStartGame(); + }); + return; + } + goto IL_675; case (int)TagAlias.Disconnect: { DisconnectReasons reason3 = DisconnectReasons.ServerRequest; @@ -820,7 +870,7 @@ namespace InnerNet this.EnqueueDisconnect(reason3, null); return; } - case Tags.RemovePlayer: + case Tags.RemovePlayer: // MsgRead:RemovePlayer , 这里不知道为什么没处理 break; case (int)TagAlias.GameData: case (int)TagAlias.GameDataTo: // 把这类消息存在队列里,主线程后续调用 @@ -866,9 +916,33 @@ namespace InnerNet } return; } - case (int)TagAlias.JoinGame: - goto IL_235; - case (int)TagAlias.Gameover: + case (int)Tags.JoinedGame: // MsgRead:JoinedGame , 加入游戏成功的反馈,创建client实例 + goto IL_235; + IL_235: + int num6 = reader.ReadInt32(); + if (this.GameId != num6 || this.GameState == InnerNetClient.GameStates.Joined) + { + return; + } + this.GameState = InnerNetClient.GameStates.Joined; + this.ClientId = reader.ReadInt32(); + ClientData myClient = this.GetOrCreateClient(this.ClientId); + this.HostId = reader.ReadInt32(); + int num7 = reader.ReadPackedInt32(); + for (int i = 0; i < num7; i++) + { + this.GetOrCreateClient(reader.ReadPackedInt32()); + } + obj = this.Dispatcher; + lock (obj) + { + this.Dispatcher.Add(delegate + { + this.OnGameJoined(InnerNetClient.IntToGameName(this.GameId), myClient); + }); + return; + } + case Tags.EndGame: // MsgRead:EndGame , 结束游戏 { int num3 = reader.ReadInt32(); if (this.GameId == num3 && this.GameState != InnerNetClient.GameStates.Ended) @@ -894,15 +968,73 @@ namespace InnerNet } return; } - case 9: - goto IL_517; - case 10: - goto IL_5BC; - case 11: - goto IL_675; - case 12: - goto IL_1DD; - case 13: + case Tags.GetGameList: // MsgRead:GetGameList , 获得游戏房间列表 + goto IL_517; + IL_517: + int totalGames = reader.ReadPackedInt32(); + List output = new List(); // 房间 + while (reader.Position < reader.Length) + { + output.Add(new GameListing(reader.ReadInt32(), reader.ReadByte(), reader.ReadByte(), reader.ReadByte(), reader.ReadPackedInt32(), reader.ReadString())); + } + obj = this.Dispatcher; + lock (obj) + { + this.Dispatcher.Add(delegate + { + this.OnGetGameList(totalGames, output); + }); + return; + } + case Tags.AlterGame: // MsgRead:AlterGame + goto IL_5BC; + IL_5BC: + int num10 = reader.ReadInt32(); + if (this.GameId != num10) + { + return; + } + byte b = reader.ReadByte(); + if (b == 1) + { + this.IsGamePublic = reader.ReadBoolean(); + string str = "Alter Public = "; + bool flag = this.IsGamePublic; + Debug.Log(str + flag.ToString()); + return; + } + Debug.Log("Alter unknown"); + return; + case Tags.KickPlayer: // MsgRead:KickPlayer , 被踢掉 + goto IL_675; + IL_675: + int num11 = reader.ReadInt32(); + if (this.GameId == num11 && reader.ReadPackedInt32() == this.ClientId) + { + this.EnqueueDisconnect(reader.ReadBoolean() ? DisconnectReasons.Banned : DisconnectReasons.Kicked, null); + return; + } + return; + case Tags.WaitForHost: // MsgRead:WaitForHost , 等主机进行操作 + goto IL_1DD; + IL_1DD: + int num5 = reader.ReadInt32(); + if (this.GameId != num5) + { + return; + } + this.ClientId = reader.ReadInt32(); + obj = this.Dispatcher; + lock (obj) + { + this.Dispatcher.Add(delegate + { + // 这里会弹出一个等待主机操作的界面 + this.OnWaitForHost(InnerNetClient.IntToGameName(this.GameId)); + }); + return; + } + case Tags.Redirect: // MsgRead:Redirect { uint address = reader.ReadUInt32(); ushort port = reader.ReadUInt16(); @@ -948,132 +1080,6 @@ namespace InnerNet return; } return; - IL_1DD: - int num5 = reader.ReadInt32(); - if (this.GameId != num5) - { - return; - } - this.ClientId = reader.ReadInt32(); - obj = this.Dispatcher; - lock (obj) - { - this.Dispatcher.Add(delegate - { - this.OnWaitForHost(InnerNetClient.IntToGameName(this.GameId)); - }); - return; - } - IL_235: - int num6 = reader.ReadInt32(); - if (this.GameId != num6 || this.GameState == InnerNetClient.GameStates.Joined) - { - return; - } - this.GameState = InnerNetClient.GameStates.Joined; - this.ClientId = reader.ReadInt32(); - ClientData myClient = this.GetOrCreateClient(this.ClientId); - this.HostId = reader.ReadInt32(); - int num7 = reader.ReadPackedInt32(); - for (int i = 0; i < num7; i++) - { - this.GetOrCreateClient(reader.ReadPackedInt32()); - } - obj = this.Dispatcher; - lock (obj) - { - this.Dispatcher.Add(delegate - { - this.OnGameJoined(InnerNetClient.IntToGameName(this.GameId), myClient); - }); - return; - } - IL_2F5: // 同时处理join game和disconnect - int num8 = reader.ReadInt32(); - DisconnectReasons disconnectReasons = (DisconnectReasons)num8; - if (InnerNetClient.disconnectReasons.Contains(disconnectReasons)) - { - if (disconnectReasons == DisconnectReasons.Custom) - { - this.LastCustomDisconnect = reader.ReadString(); - } - this.GameId = -1; - this.EnqueueDisconnect(disconnectReasons, null); - return; - } - if (this.GameId == num8) - { - int num9 = reader.ReadInt32(); - bool amHost = this.AmHost; - this.HostId = reader.ReadInt32(); - ClientData client = this.GetOrCreateClient(num9); - Debug.Log(string.Format("Player {0} joined", num9)); - obj = this.Dispatcher; - lock (obj) - { - this.Dispatcher.Add(delegate - { - // 某个玩家加入了本局 - this.OnPlayerJoined(client); - }); - } - if (!this.AmHost || amHost) - { - return; - } - obj = this.Dispatcher; - lock (obj) - { - this.Dispatcher.Add(delegate - { - this.OnBecomeHost(); - }); - return; - } - } - this.EnqueueDisconnect(DisconnectReasons.IncorrectGame, null); - return; - IL_517: - int totalGames = reader.ReadPackedInt32(); - List output = new List(); - while (reader.Position < reader.Length) - { - output.Add(new GameListing(reader.ReadInt32(), reader.ReadByte(), reader.ReadByte(), reader.ReadByte(), reader.ReadPackedInt32(), reader.ReadString())); - } - obj = this.Dispatcher; - lock (obj) - { - this.Dispatcher.Add(delegate - { - this.OnGetGameList(totalGames, output); - }); - return; - } - IL_5BC: - int num10 = reader.ReadInt32(); - if (this.GameId != num10) - { - return; - } - byte b = reader.ReadByte(); - if (b == 1) - { - this.IsGamePublic = reader.ReadBoolean(); - string str = "Alter Public = "; - bool flag = this.IsGamePublic; - Debug.Log(str + flag.ToString()); - return; - } - Debug.Log("Alter unknown"); - return; - IL_675: - int num11 = reader.ReadInt32(); - if (this.GameId == num11 && reader.ReadPackedInt32() == this.ClientId) - { - this.EnqueueDisconnect(reader.ReadBoolean() ? DisconnectReasons.Banned : DisconnectReasons.Kicked, null); - return; - } - return; IL_70A: Debug.Log(string.Format("Bad tag {0} at {1}+{2}={3}: ", new object[] { -- cgit v1.1-26-g67d0