962 lines
27 KiB
C#
962 lines
27 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using UnityEngine.Networking.NetworkSystem;
|
|
using UnityEngine.SceneManagement;
|
|
|
|
namespace UnityEngine.Networking
|
|
{
|
|
// Token: 0x02000048 RID: 72
|
|
[AddComponentMenu("Network/NetworkLobbyManager")]
|
|
public class NetworkLobbyManager : NetworkManager
|
|
{
|
|
// Token: 0x17000060 RID: 96
|
|
// (get) Token: 0x06000254 RID: 596 RVA: 0x0000FE78 File Offset: 0x0000E078
|
|
// (set) Token: 0x06000255 RID: 597 RVA: 0x0000FE93 File Offset: 0x0000E093
|
|
public bool showLobbyGUI
|
|
{
|
|
get
|
|
{
|
|
return this.m_ShowLobbyGUI;
|
|
}
|
|
set
|
|
{
|
|
this.m_ShowLobbyGUI = value;
|
|
}
|
|
}
|
|
|
|
// Token: 0x17000061 RID: 97
|
|
// (get) Token: 0x06000256 RID: 598 RVA: 0x0000FEA0 File Offset: 0x0000E0A0
|
|
// (set) Token: 0x06000257 RID: 599 RVA: 0x0000FEBB File Offset: 0x0000E0BB
|
|
public int maxPlayers
|
|
{
|
|
get
|
|
{
|
|
return this.m_MaxPlayers;
|
|
}
|
|
set
|
|
{
|
|
this.m_MaxPlayers = value;
|
|
}
|
|
}
|
|
|
|
// Token: 0x17000062 RID: 98
|
|
// (get) Token: 0x06000258 RID: 600 RVA: 0x0000FEC8 File Offset: 0x0000E0C8
|
|
// (set) Token: 0x06000259 RID: 601 RVA: 0x0000FEE3 File Offset: 0x0000E0E3
|
|
public int maxPlayersPerConnection
|
|
{
|
|
get
|
|
{
|
|
return this.m_MaxPlayersPerConnection;
|
|
}
|
|
set
|
|
{
|
|
this.m_MaxPlayersPerConnection = value;
|
|
}
|
|
}
|
|
|
|
// Token: 0x17000063 RID: 99
|
|
// (get) Token: 0x0600025A RID: 602 RVA: 0x0000FEF0 File Offset: 0x0000E0F0
|
|
// (set) Token: 0x0600025B RID: 603 RVA: 0x0000FF0B File Offset: 0x0000E10B
|
|
public int minPlayers
|
|
{
|
|
get
|
|
{
|
|
return this.m_MinPlayers;
|
|
}
|
|
set
|
|
{
|
|
this.m_MinPlayers = value;
|
|
}
|
|
}
|
|
|
|
// Token: 0x17000064 RID: 100
|
|
// (get) Token: 0x0600025C RID: 604 RVA: 0x0000FF18 File Offset: 0x0000E118
|
|
// (set) Token: 0x0600025D RID: 605 RVA: 0x0000FF33 File Offset: 0x0000E133
|
|
public NetworkLobbyPlayer lobbyPlayerPrefab
|
|
{
|
|
get
|
|
{
|
|
return this.m_LobbyPlayerPrefab;
|
|
}
|
|
set
|
|
{
|
|
this.m_LobbyPlayerPrefab = value;
|
|
}
|
|
}
|
|
|
|
// Token: 0x17000065 RID: 101
|
|
// (get) Token: 0x0600025E RID: 606 RVA: 0x0000FF40 File Offset: 0x0000E140
|
|
// (set) Token: 0x0600025F RID: 607 RVA: 0x0000FF5B File Offset: 0x0000E15B
|
|
public GameObject gamePlayerPrefab
|
|
{
|
|
get
|
|
{
|
|
return this.m_GamePlayerPrefab;
|
|
}
|
|
set
|
|
{
|
|
this.m_GamePlayerPrefab = value;
|
|
}
|
|
}
|
|
|
|
// Token: 0x17000066 RID: 102
|
|
// (get) Token: 0x06000260 RID: 608 RVA: 0x0000FF68 File Offset: 0x0000E168
|
|
// (set) Token: 0x06000261 RID: 609 RVA: 0x0000FF83 File Offset: 0x0000E183
|
|
public string lobbyScene
|
|
{
|
|
get
|
|
{
|
|
return this.m_LobbyScene;
|
|
}
|
|
set
|
|
{
|
|
this.m_LobbyScene = value;
|
|
base.offlineScene = value;
|
|
}
|
|
}
|
|
|
|
// Token: 0x17000067 RID: 103
|
|
// (get) Token: 0x06000262 RID: 610 RVA: 0x0000FF94 File Offset: 0x0000E194
|
|
// (set) Token: 0x06000263 RID: 611 RVA: 0x0000FFAF File Offset: 0x0000E1AF
|
|
public string playScene
|
|
{
|
|
get
|
|
{
|
|
return this.m_PlayScene;
|
|
}
|
|
set
|
|
{
|
|
this.m_PlayScene = value;
|
|
}
|
|
}
|
|
|
|
// Token: 0x06000264 RID: 612 RVA: 0x0000FFBC File Offset: 0x0000E1BC
|
|
private void OnValidate()
|
|
{
|
|
if (this.m_MaxPlayers <= 0)
|
|
{
|
|
this.m_MaxPlayers = 1;
|
|
}
|
|
if (this.m_MaxPlayersPerConnection <= 0)
|
|
{
|
|
this.m_MaxPlayersPerConnection = 1;
|
|
}
|
|
if (this.m_MaxPlayersPerConnection > this.maxPlayers)
|
|
{
|
|
this.m_MaxPlayersPerConnection = this.maxPlayers;
|
|
}
|
|
if (this.m_MinPlayers < 0)
|
|
{
|
|
this.m_MinPlayers = 0;
|
|
}
|
|
if (this.m_MinPlayers > this.m_MaxPlayers)
|
|
{
|
|
this.m_MinPlayers = this.m_MaxPlayers;
|
|
}
|
|
if (this.m_LobbyPlayerPrefab != null)
|
|
{
|
|
NetworkIdentity component = this.m_LobbyPlayerPrefab.GetComponent<NetworkIdentity>();
|
|
if (component == null)
|
|
{
|
|
this.m_LobbyPlayerPrefab = null;
|
|
Debug.LogWarning("LobbyPlayer prefab must have a NetworkIdentity component.");
|
|
}
|
|
}
|
|
if (this.m_GamePlayerPrefab != null)
|
|
{
|
|
NetworkIdentity component2 = this.m_GamePlayerPrefab.GetComponent<NetworkIdentity>();
|
|
if (component2 == null)
|
|
{
|
|
this.m_GamePlayerPrefab = null;
|
|
Debug.LogWarning("GamePlayer prefab must have a NetworkIdentity component.");
|
|
}
|
|
}
|
|
}
|
|
|
|
// Token: 0x06000265 RID: 613 RVA: 0x000100C4 File Offset: 0x0000E2C4
|
|
private byte FindSlot()
|
|
{
|
|
byte b = 0;
|
|
while ((int)b < this.maxPlayers)
|
|
{
|
|
if (this.lobbySlots[(int)b] == null)
|
|
{
|
|
return b;
|
|
}
|
|
b += 1;
|
|
}
|
|
return byte.MaxValue;
|
|
}
|
|
|
|
// Token: 0x06000266 RID: 614 RVA: 0x00010114 File Offset: 0x0000E314
|
|
private void SceneLoadedForPlayer(NetworkConnection conn, GameObject lobbyPlayerGameObject)
|
|
{
|
|
NetworkLobbyPlayer component = lobbyPlayerGameObject.GetComponent<NetworkLobbyPlayer>();
|
|
if (!(component == null))
|
|
{
|
|
string name = SceneManager.GetSceneAt(0).name;
|
|
if (LogFilter.logDebug)
|
|
{
|
|
Debug.Log(string.Concat(new object[] { "NetworkLobby SceneLoadedForPlayer scene:", name, " ", conn }));
|
|
}
|
|
if (name == this.m_LobbyScene)
|
|
{
|
|
NetworkLobbyManager.PendingPlayer pendingPlayer;
|
|
pendingPlayer.conn = conn;
|
|
pendingPlayer.lobbyPlayer = lobbyPlayerGameObject;
|
|
this.m_PendingPlayers.Add(pendingPlayer);
|
|
}
|
|
else
|
|
{
|
|
short playerControllerId = lobbyPlayerGameObject.GetComponent<NetworkIdentity>().playerControllerId;
|
|
GameObject gameObject = this.OnLobbyServerCreateGamePlayer(conn, playerControllerId);
|
|
if (gameObject == null)
|
|
{
|
|
Transform startPosition = base.GetStartPosition();
|
|
if (startPosition != null)
|
|
{
|
|
gameObject = Object.Instantiate<GameObject>(this.gamePlayerPrefab, startPosition.position, startPosition.rotation);
|
|
}
|
|
else
|
|
{
|
|
gameObject = Object.Instantiate<GameObject>(this.gamePlayerPrefab, Vector3.zero, Quaternion.identity);
|
|
}
|
|
}
|
|
if (this.OnLobbyServerSceneLoadedForPlayer(lobbyPlayerGameObject, gameObject))
|
|
{
|
|
NetworkServer.ReplacePlayerForConnection(conn, gameObject, playerControllerId);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// Token: 0x06000267 RID: 615 RVA: 0x00010248 File Offset: 0x0000E448
|
|
private static int CheckConnectionIsReadyToBegin(NetworkConnection conn)
|
|
{
|
|
int num = 0;
|
|
for (int i = 0; i < conn.playerControllers.Count; i++)
|
|
{
|
|
PlayerController playerController = conn.playerControllers[i];
|
|
if (playerController.IsValid)
|
|
{
|
|
NetworkLobbyPlayer component = playerController.gameObject.GetComponent<NetworkLobbyPlayer>();
|
|
if (component.readyToBegin)
|
|
{
|
|
num++;
|
|
}
|
|
}
|
|
}
|
|
return num;
|
|
}
|
|
|
|
// Token: 0x06000268 RID: 616 RVA: 0x000102B8 File Offset: 0x0000E4B8
|
|
public void CheckReadyToBegin()
|
|
{
|
|
string name = SceneManager.GetSceneAt(0).name;
|
|
if (!(name != this.m_LobbyScene))
|
|
{
|
|
int num = 0;
|
|
int num2 = 0;
|
|
for (int i = 0; i < NetworkServer.connections.Count; i++)
|
|
{
|
|
NetworkConnection networkConnection = NetworkServer.connections[i];
|
|
if (networkConnection != null)
|
|
{
|
|
num2++;
|
|
num += NetworkLobbyManager.CheckConnectionIsReadyToBegin(networkConnection);
|
|
}
|
|
}
|
|
if (this.m_MinPlayers <= 0 || num >= this.m_MinPlayers)
|
|
{
|
|
if (num >= num2)
|
|
{
|
|
this.m_PendingPlayers.Clear();
|
|
this.OnLobbyServerPlayersReady();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// Token: 0x06000269 RID: 617 RVA: 0x00010375 File Offset: 0x0000E575
|
|
public void ServerReturnToLobby()
|
|
{
|
|
if (!NetworkServer.active)
|
|
{
|
|
Debug.Log("ServerReturnToLobby called on client");
|
|
}
|
|
else
|
|
{
|
|
this.ServerChangeScene(this.m_LobbyScene);
|
|
}
|
|
}
|
|
|
|
// Token: 0x0600026A RID: 618 RVA: 0x000103A0 File Offset: 0x0000E5A0
|
|
private void CallOnClientEnterLobby()
|
|
{
|
|
this.OnLobbyClientEnter();
|
|
for (int i = 0; i < this.lobbySlots.Length; i++)
|
|
{
|
|
NetworkLobbyPlayer networkLobbyPlayer = this.lobbySlots[i];
|
|
if (!(networkLobbyPlayer == null))
|
|
{
|
|
networkLobbyPlayer.readyToBegin = false;
|
|
networkLobbyPlayer.OnClientEnterLobby();
|
|
}
|
|
}
|
|
}
|
|
|
|
// Token: 0x0600026B RID: 619 RVA: 0x000103F8 File Offset: 0x0000E5F8
|
|
private void CallOnClientExitLobby()
|
|
{
|
|
this.OnLobbyClientExit();
|
|
for (int i = 0; i < this.lobbySlots.Length; i++)
|
|
{
|
|
NetworkLobbyPlayer networkLobbyPlayer = this.lobbySlots[i];
|
|
if (!(networkLobbyPlayer == null))
|
|
{
|
|
networkLobbyPlayer.OnClientExitLobby();
|
|
}
|
|
}
|
|
}
|
|
|
|
// Token: 0x0600026C RID: 620 RVA: 0x00010448 File Offset: 0x0000E648
|
|
public bool SendReturnToLobby()
|
|
{
|
|
bool flag;
|
|
if (this.client == null || !this.client.isConnected)
|
|
{
|
|
flag = false;
|
|
}
|
|
else
|
|
{
|
|
EmptyMessage emptyMessage = new EmptyMessage();
|
|
this.client.Send(46, emptyMessage);
|
|
flag = true;
|
|
}
|
|
return flag;
|
|
}
|
|
|
|
// Token: 0x0600026D RID: 621 RVA: 0x00010498 File Offset: 0x0000E698
|
|
public override void OnServerConnect(NetworkConnection conn)
|
|
{
|
|
if (base.numPlayers > this.maxPlayers)
|
|
{
|
|
if (LogFilter.logWarn)
|
|
{
|
|
Debug.LogWarning("NetworkLobbyManager can't accept new connection [" + conn + "], too many players connected.");
|
|
}
|
|
conn.Disconnect();
|
|
}
|
|
else
|
|
{
|
|
string name = SceneManager.GetSceneAt(0).name;
|
|
if (name != this.m_LobbyScene)
|
|
{
|
|
if (LogFilter.logWarn)
|
|
{
|
|
Debug.LogWarning("NetworkLobbyManager can't accept new connection [" + conn + "], not in lobby and game already in progress.");
|
|
}
|
|
conn.Disconnect();
|
|
}
|
|
else
|
|
{
|
|
base.OnServerConnect(conn);
|
|
for (int i = 0; i < this.lobbySlots.Length; i++)
|
|
{
|
|
if (this.lobbySlots[i])
|
|
{
|
|
this.lobbySlots[i].SetDirtyBit(1U);
|
|
}
|
|
}
|
|
this.OnLobbyServerConnect(conn);
|
|
}
|
|
}
|
|
}
|
|
|
|
// Token: 0x0600026E RID: 622 RVA: 0x0001057C File Offset: 0x0000E77C
|
|
public override void OnServerDisconnect(NetworkConnection conn)
|
|
{
|
|
base.OnServerDisconnect(conn);
|
|
for (int i = 0; i < this.lobbySlots.Length; i++)
|
|
{
|
|
NetworkLobbyPlayer networkLobbyPlayer = this.lobbySlots[i];
|
|
if (!(networkLobbyPlayer == null))
|
|
{
|
|
if (networkLobbyPlayer.connectionToClient == conn)
|
|
{
|
|
this.lobbySlots[i] = null;
|
|
NetworkServer.Destroy(networkLobbyPlayer.gameObject);
|
|
}
|
|
}
|
|
}
|
|
this.OnLobbyServerDisconnect(conn);
|
|
}
|
|
|
|
// Token: 0x0600026F RID: 623 RVA: 0x000105F0 File Offset: 0x0000E7F0
|
|
public override void OnServerAddPlayer(NetworkConnection conn, short playerControllerId)
|
|
{
|
|
string name = SceneManager.GetSceneAt(0).name;
|
|
if (!(name != this.m_LobbyScene))
|
|
{
|
|
int num = 0;
|
|
for (int i = 0; i < conn.playerControllers.Count; i++)
|
|
{
|
|
if (conn.playerControllers[i].IsValid)
|
|
{
|
|
num++;
|
|
}
|
|
}
|
|
if (num >= this.maxPlayersPerConnection)
|
|
{
|
|
if (LogFilter.logWarn)
|
|
{
|
|
Debug.LogWarning("NetworkLobbyManager no more players for this connection.");
|
|
}
|
|
EmptyMessage emptyMessage = new EmptyMessage();
|
|
conn.Send(45, emptyMessage);
|
|
}
|
|
else
|
|
{
|
|
byte b = this.FindSlot();
|
|
if (b == 255)
|
|
{
|
|
if (LogFilter.logWarn)
|
|
{
|
|
Debug.LogWarning("NetworkLobbyManager no space for more players");
|
|
}
|
|
EmptyMessage emptyMessage2 = new EmptyMessage();
|
|
conn.Send(45, emptyMessage2);
|
|
}
|
|
else
|
|
{
|
|
GameObject gameObject = this.OnLobbyServerCreateLobbyPlayer(conn, playerControllerId);
|
|
if (gameObject == null)
|
|
{
|
|
gameObject = Object.Instantiate<GameObject>(this.lobbyPlayerPrefab.gameObject, Vector3.zero, Quaternion.identity);
|
|
}
|
|
NetworkLobbyPlayer component = gameObject.GetComponent<NetworkLobbyPlayer>();
|
|
component.slot = b;
|
|
this.lobbySlots[(int)b] = component;
|
|
NetworkServer.AddPlayerForConnection(conn, gameObject, playerControllerId);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// Token: 0x06000270 RID: 624 RVA: 0x00010738 File Offset: 0x0000E938
|
|
public override void OnServerRemovePlayer(NetworkConnection conn, PlayerController player)
|
|
{
|
|
short playerControllerId = player.playerControllerId;
|
|
byte slot = player.gameObject.GetComponent<NetworkLobbyPlayer>().slot;
|
|
this.lobbySlots[(int)slot] = null;
|
|
base.OnServerRemovePlayer(conn, player);
|
|
for (int i = 0; i < this.lobbySlots.Length; i++)
|
|
{
|
|
NetworkLobbyPlayer networkLobbyPlayer = this.lobbySlots[i];
|
|
if (networkLobbyPlayer != null)
|
|
{
|
|
networkLobbyPlayer.GetComponent<NetworkLobbyPlayer>().readyToBegin = false;
|
|
NetworkLobbyManager.s_LobbyReadyToBeginMessage.slotId = networkLobbyPlayer.slot;
|
|
NetworkLobbyManager.s_LobbyReadyToBeginMessage.readyState = false;
|
|
NetworkServer.SendToReady(null, 43, NetworkLobbyManager.s_LobbyReadyToBeginMessage);
|
|
}
|
|
}
|
|
this.OnLobbyServerPlayerRemoved(conn, playerControllerId);
|
|
}
|
|
|
|
// Token: 0x06000271 RID: 625 RVA: 0x000107E0 File Offset: 0x0000E9E0
|
|
public override void ServerChangeScene(string sceneName)
|
|
{
|
|
if (sceneName == this.m_LobbyScene)
|
|
{
|
|
for (int i = 0; i < this.lobbySlots.Length; i++)
|
|
{
|
|
NetworkLobbyPlayer networkLobbyPlayer = this.lobbySlots[i];
|
|
if (!(networkLobbyPlayer == null))
|
|
{
|
|
NetworkIdentity component = networkLobbyPlayer.GetComponent<NetworkIdentity>();
|
|
PlayerController playerController;
|
|
if (component.connectionToClient.GetPlayerController(component.playerControllerId, out playerController))
|
|
{
|
|
NetworkServer.Destroy(playerController.gameObject);
|
|
}
|
|
if (NetworkServer.active)
|
|
{
|
|
networkLobbyPlayer.GetComponent<NetworkLobbyPlayer>().readyToBegin = false;
|
|
NetworkServer.ReplacePlayerForConnection(component.connectionToClient, networkLobbyPlayer.gameObject, component.playerControllerId);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
base.ServerChangeScene(sceneName);
|
|
}
|
|
|
|
// Token: 0x06000272 RID: 626 RVA: 0x0001089C File Offset: 0x0000EA9C
|
|
public override void OnServerSceneChanged(string sceneName)
|
|
{
|
|
if (sceneName != this.m_LobbyScene)
|
|
{
|
|
for (int i = 0; i < this.m_PendingPlayers.Count; i++)
|
|
{
|
|
NetworkLobbyManager.PendingPlayer pendingPlayer = this.m_PendingPlayers[i];
|
|
this.SceneLoadedForPlayer(pendingPlayer.conn, pendingPlayer.lobbyPlayer);
|
|
}
|
|
this.m_PendingPlayers.Clear();
|
|
}
|
|
this.OnLobbyServerSceneChanged(sceneName);
|
|
}
|
|
|
|
// Token: 0x06000273 RID: 627 RVA: 0x00010910 File Offset: 0x0000EB10
|
|
private void OnServerReadyToBeginMessage(NetworkMessage netMsg)
|
|
{
|
|
if (LogFilter.logDebug)
|
|
{
|
|
Debug.Log("NetworkLobbyManager OnServerReadyToBeginMessage");
|
|
}
|
|
netMsg.ReadMessage<LobbyReadyToBeginMessage>(NetworkLobbyManager.s_ReadyToBeginMessage);
|
|
PlayerController playerController;
|
|
if (!netMsg.conn.GetPlayerController((short)NetworkLobbyManager.s_ReadyToBeginMessage.slotId, out playerController))
|
|
{
|
|
if (LogFilter.logError)
|
|
{
|
|
Debug.LogError("NetworkLobbyManager OnServerReadyToBeginMessage invalid playerControllerId " + NetworkLobbyManager.s_ReadyToBeginMessage.slotId);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
NetworkLobbyPlayer component = playerController.gameObject.GetComponent<NetworkLobbyPlayer>();
|
|
component.readyToBegin = NetworkLobbyManager.s_ReadyToBeginMessage.readyState;
|
|
NetworkServer.SendToReady(null, 43, new LobbyReadyToBeginMessage
|
|
{
|
|
slotId = component.slot,
|
|
readyState = NetworkLobbyManager.s_ReadyToBeginMessage.readyState
|
|
});
|
|
this.CheckReadyToBegin();
|
|
}
|
|
}
|
|
|
|
// Token: 0x06000274 RID: 628 RVA: 0x000109DC File Offset: 0x0000EBDC
|
|
private void OnServerSceneLoadedMessage(NetworkMessage netMsg)
|
|
{
|
|
if (LogFilter.logDebug)
|
|
{
|
|
Debug.Log("NetworkLobbyManager OnSceneLoadedMessage");
|
|
}
|
|
netMsg.ReadMessage<IntegerMessage>(NetworkLobbyManager.s_SceneLoadedMessage);
|
|
PlayerController playerController;
|
|
if (!netMsg.conn.GetPlayerController((short)NetworkLobbyManager.s_SceneLoadedMessage.value, out playerController))
|
|
{
|
|
if (LogFilter.logError)
|
|
{
|
|
Debug.LogError("NetworkLobbyManager OnServerSceneLoadedMessage invalid playerControllerId " + NetworkLobbyManager.s_SceneLoadedMessage.value);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
this.SceneLoadedForPlayer(netMsg.conn, playerController.gameObject);
|
|
}
|
|
}
|
|
|
|
// Token: 0x06000275 RID: 629 RVA: 0x00010A6A File Offset: 0x0000EC6A
|
|
private void OnServerReturnToLobbyMessage(NetworkMessage netMsg)
|
|
{
|
|
if (LogFilter.logDebug)
|
|
{
|
|
Debug.Log("NetworkLobbyManager OnServerReturnToLobbyMessage");
|
|
}
|
|
this.ServerReturnToLobby();
|
|
}
|
|
|
|
// Token: 0x06000276 RID: 630 RVA: 0x00010A8C File Offset: 0x0000EC8C
|
|
public override void OnStartServer()
|
|
{
|
|
if (string.IsNullOrEmpty(this.m_LobbyScene))
|
|
{
|
|
if (LogFilter.logError)
|
|
{
|
|
Debug.LogError("NetworkLobbyManager LobbyScene is empty. Set the LobbyScene in the inspector for the NetworkLobbyMangaer");
|
|
}
|
|
}
|
|
else if (string.IsNullOrEmpty(this.m_PlayScene))
|
|
{
|
|
if (LogFilter.logError)
|
|
{
|
|
Debug.LogError("NetworkLobbyManager PlayScene is empty. Set the PlayScene in the inspector for the NetworkLobbyMangaer");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (this.lobbySlots.Length == 0)
|
|
{
|
|
this.lobbySlots = new NetworkLobbyPlayer[this.maxPlayers];
|
|
}
|
|
NetworkServer.RegisterHandler(43, new NetworkMessageDelegate(this.OnServerReadyToBeginMessage));
|
|
NetworkServer.RegisterHandler(44, new NetworkMessageDelegate(this.OnServerSceneLoadedMessage));
|
|
NetworkServer.RegisterHandler(46, new NetworkMessageDelegate(this.OnServerReturnToLobbyMessage));
|
|
this.OnLobbyStartServer();
|
|
}
|
|
}
|
|
|
|
// Token: 0x06000277 RID: 631 RVA: 0x00010B51 File Offset: 0x0000ED51
|
|
public override void OnStartHost()
|
|
{
|
|
this.OnLobbyStartHost();
|
|
}
|
|
|
|
// Token: 0x06000278 RID: 632 RVA: 0x00010B5A File Offset: 0x0000ED5A
|
|
public override void OnStopHost()
|
|
{
|
|
this.OnLobbyStopHost();
|
|
}
|
|
|
|
// Token: 0x06000279 RID: 633 RVA: 0x00010B64 File Offset: 0x0000ED64
|
|
public override void OnStartClient(NetworkClient lobbyClient)
|
|
{
|
|
if (this.lobbySlots.Length == 0)
|
|
{
|
|
this.lobbySlots = new NetworkLobbyPlayer[this.maxPlayers];
|
|
}
|
|
if (this.m_LobbyPlayerPrefab == null || this.m_LobbyPlayerPrefab.gameObject == null)
|
|
{
|
|
if (LogFilter.logError)
|
|
{
|
|
Debug.LogError("NetworkLobbyManager no LobbyPlayer prefab is registered. Please add a LobbyPlayer prefab.");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
ClientScene.RegisterPrefab(this.m_LobbyPlayerPrefab.gameObject);
|
|
}
|
|
if (this.m_GamePlayerPrefab == null)
|
|
{
|
|
if (LogFilter.logError)
|
|
{
|
|
Debug.LogError("NetworkLobbyManager no GamePlayer prefab is registered. Please add a GamePlayer prefab.");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
ClientScene.RegisterPrefab(this.m_GamePlayerPrefab);
|
|
}
|
|
lobbyClient.RegisterHandler(43, new NetworkMessageDelegate(this.OnClientReadyToBegin));
|
|
lobbyClient.RegisterHandler(45, new NetworkMessageDelegate(this.OnClientAddPlayerFailedMessage));
|
|
this.OnLobbyStartClient(lobbyClient);
|
|
}
|
|
|
|
// Token: 0x0600027A RID: 634 RVA: 0x00010C52 File Offset: 0x0000EE52
|
|
public override void OnClientConnect(NetworkConnection conn)
|
|
{
|
|
this.OnLobbyClientConnect(conn);
|
|
this.CallOnClientEnterLobby();
|
|
base.OnClientConnect(conn);
|
|
}
|
|
|
|
// Token: 0x0600027B RID: 635 RVA: 0x00010C69 File Offset: 0x0000EE69
|
|
public override void OnClientDisconnect(NetworkConnection conn)
|
|
{
|
|
this.OnLobbyClientDisconnect(conn);
|
|
base.OnClientDisconnect(conn);
|
|
}
|
|
|
|
// Token: 0x0600027C RID: 636 RVA: 0x00010C7A File Offset: 0x0000EE7A
|
|
public override void OnStopClient()
|
|
{
|
|
this.OnLobbyStopClient();
|
|
this.CallOnClientExitLobby();
|
|
}
|
|
|
|
// Token: 0x0600027D RID: 637 RVA: 0x00010C8C File Offset: 0x0000EE8C
|
|
public override void OnClientSceneChanged(NetworkConnection conn)
|
|
{
|
|
string name = SceneManager.GetSceneAt(0).name;
|
|
if (name == this.m_LobbyScene)
|
|
{
|
|
if (this.client.isConnected)
|
|
{
|
|
this.CallOnClientEnterLobby();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
this.CallOnClientExitLobby();
|
|
}
|
|
base.OnClientSceneChanged(conn);
|
|
this.OnLobbyClientSceneChanged(conn);
|
|
}
|
|
|
|
// Token: 0x0600027E RID: 638 RVA: 0x00010CF0 File Offset: 0x0000EEF0
|
|
private void OnClientReadyToBegin(NetworkMessage netMsg)
|
|
{
|
|
netMsg.ReadMessage<LobbyReadyToBeginMessage>(NetworkLobbyManager.s_LobbyReadyToBeginMessage);
|
|
if ((int)NetworkLobbyManager.s_LobbyReadyToBeginMessage.slotId >= this.lobbySlots.Count<NetworkLobbyPlayer>())
|
|
{
|
|
if (LogFilter.logError)
|
|
{
|
|
Debug.LogError("NetworkLobbyManager OnClientReadyToBegin invalid lobby slot " + NetworkLobbyManager.s_LobbyReadyToBeginMessage.slotId);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
NetworkLobbyPlayer networkLobbyPlayer = this.lobbySlots[(int)NetworkLobbyManager.s_LobbyReadyToBeginMessage.slotId];
|
|
if (networkLobbyPlayer == null || networkLobbyPlayer.gameObject == null)
|
|
{
|
|
if (LogFilter.logError)
|
|
{
|
|
Debug.LogError("NetworkLobbyManager OnClientReadyToBegin no player at lobby slot " + NetworkLobbyManager.s_LobbyReadyToBeginMessage.slotId);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
networkLobbyPlayer.readyToBegin = NetworkLobbyManager.s_LobbyReadyToBeginMessage.readyState;
|
|
networkLobbyPlayer.OnClientReady(NetworkLobbyManager.s_LobbyReadyToBeginMessage.readyState);
|
|
}
|
|
}
|
|
}
|
|
|
|
// Token: 0x0600027F RID: 639 RVA: 0x00010DD2 File Offset: 0x0000EFD2
|
|
private void OnClientAddPlayerFailedMessage(NetworkMessage netMsg)
|
|
{
|
|
if (LogFilter.logDebug)
|
|
{
|
|
Debug.Log("NetworkLobbyManager Add Player failed.");
|
|
}
|
|
this.OnLobbyClientAddPlayerFailed();
|
|
}
|
|
|
|
// Token: 0x06000280 RID: 640 RVA: 0x00010DF1 File Offset: 0x0000EFF1
|
|
public virtual void OnLobbyStartHost()
|
|
{
|
|
}
|
|
|
|
// Token: 0x06000281 RID: 641 RVA: 0x00010DF4 File Offset: 0x0000EFF4
|
|
public virtual void OnLobbyStopHost()
|
|
{
|
|
}
|
|
|
|
// Token: 0x06000282 RID: 642 RVA: 0x00010DF7 File Offset: 0x0000EFF7
|
|
public virtual void OnLobbyStartServer()
|
|
{
|
|
}
|
|
|
|
// Token: 0x06000283 RID: 643 RVA: 0x00010DFA File Offset: 0x0000EFFA
|
|
public virtual void OnLobbyServerConnect(NetworkConnection conn)
|
|
{
|
|
}
|
|
|
|
// Token: 0x06000284 RID: 644 RVA: 0x00010DFD File Offset: 0x0000EFFD
|
|
public virtual void OnLobbyServerDisconnect(NetworkConnection conn)
|
|
{
|
|
}
|
|
|
|
// Token: 0x06000285 RID: 645 RVA: 0x00010E00 File Offset: 0x0000F000
|
|
public virtual void OnLobbyServerSceneChanged(string sceneName)
|
|
{
|
|
}
|
|
|
|
// Token: 0x06000286 RID: 646 RVA: 0x00010E04 File Offset: 0x0000F004
|
|
public virtual GameObject OnLobbyServerCreateLobbyPlayer(NetworkConnection conn, short playerControllerId)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
// Token: 0x06000287 RID: 647 RVA: 0x00010E1C File Offset: 0x0000F01C
|
|
public virtual GameObject OnLobbyServerCreateGamePlayer(NetworkConnection conn, short playerControllerId)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
// Token: 0x06000288 RID: 648 RVA: 0x00010E32 File Offset: 0x0000F032
|
|
public virtual void OnLobbyServerPlayerRemoved(NetworkConnection conn, short playerControllerId)
|
|
{
|
|
}
|
|
|
|
// Token: 0x06000289 RID: 649 RVA: 0x00010E38 File Offset: 0x0000F038
|
|
public virtual bool OnLobbyServerSceneLoadedForPlayer(GameObject lobbyPlayer, GameObject gamePlayer)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
// Token: 0x0600028A RID: 650 RVA: 0x00010E4E File Offset: 0x0000F04E
|
|
public virtual void OnLobbyServerPlayersReady()
|
|
{
|
|
this.ServerChangeScene(this.m_PlayScene);
|
|
}
|
|
|
|
// Token: 0x0600028B RID: 651 RVA: 0x00010E5D File Offset: 0x0000F05D
|
|
public virtual void OnLobbyClientEnter()
|
|
{
|
|
}
|
|
|
|
// Token: 0x0600028C RID: 652 RVA: 0x00010E60 File Offset: 0x0000F060
|
|
public virtual void OnLobbyClientExit()
|
|
{
|
|
}
|
|
|
|
// Token: 0x0600028D RID: 653 RVA: 0x00010E63 File Offset: 0x0000F063
|
|
public virtual void OnLobbyClientConnect(NetworkConnection conn)
|
|
{
|
|
}
|
|
|
|
// Token: 0x0600028E RID: 654 RVA: 0x00010E66 File Offset: 0x0000F066
|
|
public virtual void OnLobbyClientDisconnect(NetworkConnection conn)
|
|
{
|
|
}
|
|
|
|
// Token: 0x0600028F RID: 655 RVA: 0x00010E69 File Offset: 0x0000F069
|
|
public virtual void OnLobbyStartClient(NetworkClient lobbyClient)
|
|
{
|
|
}
|
|
|
|
// Token: 0x06000290 RID: 656 RVA: 0x00010E6C File Offset: 0x0000F06C
|
|
public virtual void OnLobbyStopClient()
|
|
{
|
|
}
|
|
|
|
// Token: 0x06000291 RID: 657 RVA: 0x00010E6F File Offset: 0x0000F06F
|
|
public virtual void OnLobbyClientSceneChanged(NetworkConnection conn)
|
|
{
|
|
}
|
|
|
|
// Token: 0x06000292 RID: 658 RVA: 0x00010E72 File Offset: 0x0000F072
|
|
public virtual void OnLobbyClientAddPlayerFailed()
|
|
{
|
|
}
|
|
|
|
// Token: 0x06000293 RID: 659 RVA: 0x00010E78 File Offset: 0x0000F078
|
|
private void OnGUI()
|
|
{
|
|
if (this.showLobbyGUI)
|
|
{
|
|
string name = SceneManager.GetSceneAt(0).name;
|
|
if (!(name != this.m_LobbyScene))
|
|
{
|
|
Rect rect = new Rect(90f, 180f, 500f, 150f);
|
|
GUI.Box(rect, "Players:");
|
|
if (NetworkClient.active)
|
|
{
|
|
Rect rect2 = new Rect(100f, 300f, 120f, 20f);
|
|
if (GUI.Button(rect2, "Add Player"))
|
|
{
|
|
this.TryToAddPlayer();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// Token: 0x06000294 RID: 660 RVA: 0x00010F20 File Offset: 0x0000F120
|
|
public void TryToAddPlayer()
|
|
{
|
|
if (NetworkClient.active)
|
|
{
|
|
short num = -1;
|
|
List<PlayerController> playerControllers = NetworkClient.allClients[0].connection.playerControllers;
|
|
if (playerControllers.Count < this.maxPlayers)
|
|
{
|
|
num = (short)playerControllers.Count;
|
|
}
|
|
else
|
|
{
|
|
short num2 = 0;
|
|
while ((int)num2 < this.maxPlayers)
|
|
{
|
|
if (!playerControllers[(int)num2].IsValid)
|
|
{
|
|
num = num2;
|
|
break;
|
|
}
|
|
num2 += 1;
|
|
}
|
|
}
|
|
if (LogFilter.logDebug)
|
|
{
|
|
Debug.Log(string.Concat(new object[]
|
|
{
|
|
"NetworkLobbyManager TryToAddPlayer controllerId ",
|
|
num,
|
|
" ready:",
|
|
ClientScene.ready
|
|
}));
|
|
}
|
|
if (num == -1)
|
|
{
|
|
if (LogFilter.logDebug)
|
|
{
|
|
Debug.Log("NetworkLobbyManager No Space!");
|
|
}
|
|
}
|
|
else if (ClientScene.ready)
|
|
{
|
|
ClientScene.AddPlayer(num);
|
|
}
|
|
else
|
|
{
|
|
ClientScene.AddPlayer(NetworkClient.allClients[0].connection, num);
|
|
}
|
|
}
|
|
else if (LogFilter.logDebug)
|
|
{
|
|
Debug.Log("NetworkLobbyManager NetworkClient not active!");
|
|
}
|
|
}
|
|
|
|
// Token: 0x04000144 RID: 324
|
|
[SerializeField]
|
|
private bool m_ShowLobbyGUI = true;
|
|
|
|
// Token: 0x04000145 RID: 325
|
|
[SerializeField]
|
|
private int m_MaxPlayers = 4;
|
|
|
|
// Token: 0x04000146 RID: 326
|
|
[SerializeField]
|
|
private int m_MaxPlayersPerConnection = 1;
|
|
|
|
// Token: 0x04000147 RID: 327
|
|
[SerializeField]
|
|
private int m_MinPlayers;
|
|
|
|
// Token: 0x04000148 RID: 328
|
|
[SerializeField]
|
|
private NetworkLobbyPlayer m_LobbyPlayerPrefab;
|
|
|
|
// Token: 0x04000149 RID: 329
|
|
[SerializeField]
|
|
private GameObject m_GamePlayerPrefab;
|
|
|
|
// Token: 0x0400014A RID: 330
|
|
[SerializeField]
|
|
private string m_LobbyScene = "";
|
|
|
|
// Token: 0x0400014B RID: 331
|
|
[SerializeField]
|
|
private string m_PlayScene = "";
|
|
|
|
// Token: 0x0400014C RID: 332
|
|
private List<NetworkLobbyManager.PendingPlayer> m_PendingPlayers = new List<NetworkLobbyManager.PendingPlayer>();
|
|
|
|
// Token: 0x0400014D RID: 333
|
|
public NetworkLobbyPlayer[] lobbySlots;
|
|
|
|
// Token: 0x0400014E RID: 334
|
|
private static LobbyReadyToBeginMessage s_ReadyToBeginMessage = new LobbyReadyToBeginMessage();
|
|
|
|
// Token: 0x0400014F RID: 335
|
|
private static IntegerMessage s_SceneLoadedMessage = new IntegerMessage();
|
|
|
|
// Token: 0x04000150 RID: 336
|
|
private static LobbyReadyToBeginMessage s_LobbyReadyToBeginMessage = new LobbyReadyToBeginMessage();
|
|
|
|
// Token: 0x02000049 RID: 73
|
|
private struct PendingPlayer
|
|
{
|
|
// Token: 0x04000151 RID: 337
|
|
public NetworkConnection conn;
|
|
|
|
// Token: 0x04000152 RID: 338
|
|
public GameObject lobbyPlayer;
|
|
}
|
|
}
|
|
}
|