summaryrefslogtreecommitdiff
path: root/Client/Assembly-CSharp/InnerNet
diff options
context:
space:
mode:
Diffstat (limited to 'Client/Assembly-CSharp/InnerNet')
-rw-r--r--Client/Assembly-CSharp/InnerNet/GameListing.cs1
-rw-r--r--Client/Assembly-CSharp/InnerNet/InnerNetClient.cs316
-rw-r--r--Client/Assembly-CSharp/InnerNet/InnerNetServer.cs10
3 files changed, 168 insertions, 159 deletions
diff --git a/Client/Assembly-CSharp/InnerNet/GameListing.cs b/Client/Assembly-CSharp/InnerNet/GameListing.cs
index d10ea34..8ad38a8 100644
--- a/Client/Assembly-CSharp/InnerNet/GameListing.cs
+++ b/Client/Assembly-CSharp/InnerNet/GameListing.cs
@@ -2,6 +2,7 @@
namespace InnerNet
{
+ // 游戏房间数据
[Serializable]
public struct GameListing
{
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<GameListing> output = new List<GameListing>(); // 房间
+ 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<GameListing> output = new List<GameListing>();
- 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[]
{
diff --git a/Client/Assembly-CSharp/InnerNet/InnerNetServer.cs b/Client/Assembly-CSharp/InnerNet/InnerNetServer.cs
index 3e09a4c..f0b37a1 100644
--- a/Client/Assembly-CSharp/InnerNet/InnerNetServer.cs
+++ b/Client/Assembly-CSharp/InnerNet/InnerNetServer.cs
@@ -264,7 +264,7 @@ namespace InnerNet
return;
}
break;
- case 3: // RemoveGame
+ case 3: // RemoveGame , MsgRead:RemoveGame
if (reader.ReadInt32() == 32)
{
this.ClientDisconnect(client);
@@ -333,7 +333,7 @@ namespace InnerNet
}
}
- // 踢玩家
+ // 踢玩家(断开它的连接)
private void KickPlayer(int targetId, bool ban)
{
List<InnerNetServer.Player> clients = this.Clients;
@@ -383,8 +383,8 @@ namespace InnerNet
{
MessageWriter messageWriter = MessageWriter.Get(SendOption.Reliable);
messageWriter.StartMessage(1);
- messageWriter.Write(6);
- messageWriter.EndMessage();
+ messageWriter.Write(6); // 6 = DisconnectReasons.Banned
+ messageWriter.EndMessage();
client.Connection.Send(messageWriter);
messageWriter.Recycle();
return;
@@ -452,6 +452,7 @@ namespace InnerNet
}
this.Clients.Add(client);
client.LimboState = LimboStates.WaitingForHost;
+ // MsgWrite:WaitForHost
MessageWriter messageWriter3 = MessageWriter.Get(SendOption.Reliable);
try
{
@@ -634,6 +635,7 @@ namespace InnerNet
this.Broadcast(msg, client);
}
+ // MsgWrite:JoinedGame
private void WriteJoinedMessage(InnerNetServer.Player client, MessageWriter msg, bool clear)
{
if (clear)