void Start() { clientNetworkManager = ClientNetworkManager.Instance; clientGameManager = ClientGameManager.Instance; clientEntityManager = ClientEntityManager.Instance; uiManager = UIManager.Instance; rtsCamera = FindObjectOfType <RTSCamera>(); }
public void StartAcceptClient() { if (_isFirstStartServer) { _isFirstStartServer = false; TcpConnection connection = new TcpConnection("0.0.0.0", this.port, true); serverAcceptWorker = new ServerAcceptWorker(connection); serverDetailWorker = new ServerDetailWorker(); } stop = false; playerManager = new ClientPlayerManager(); sceneManager = new ClientSceneManager(); entityManager = new ClientEntityManager(); serverAcceptWorker.Start(); serverDetailWorker.Start(); StartCoroutine(HandleNewConn()); EventManager.SendEvent(NetEventMacro.ON_SERVER_START, "127.0.0.1", this.port); }
void DarkRift_MessageReceived(object sender, MessageReceivedEventArgs e) { using (Message message = e.GetMessage()) using (DarkRiftReader reader = message.GetReader()) { if (OverallStateManager.Instance.OverallState == OverallState.IN_GAME) { if (ClientGameManager.Instance.ClientState == GameStates.GAME_IN_PROGRESS || ClientGameManager.Instance.ClientState == GameStates.WAITING_FOR_PLAYERS) { //game is in progress if (message.Tag == NetworkTags.EntityUpdate) { ClientEntityManager entityManager = ClientEntityManager.Instance; while (reader.Position < reader.Length) { string entityId = reader.ReadString(); string entityTypeId = reader.ReadString(); Entity entity = entityManager.GetEntity(entityId); if (entity == null) { entity = entityManager.CreateEntity(entityTypeId); reader.ReadSerializableInto(ref entity); //must populate entity before registering since registration depends on entity data entityManager.RegisterEntity(entity); } else { reader.ReadSerializableInto(ref entity); } } } else if (message.Tag == NetworkTags.PlayerEventUpdate) { ClientEntityManager entityManager = ClientEntityManager.Instance; while (reader.Position < reader.Length) { string playerEventId = reader.ReadString(); string playerEventTypeId = reader.ReadString(); PlayerEvent playerEvent = entityManager.GetPlayerEvent(playerEventId); if (playerEvent == null) { playerEvent = entityManager.CreatePlayerEvent(playerEventTypeId); reader.ReadSerializableInto(ref playerEvent); //must populate event before registering since registration depends on event data entityManager.RegisterPlayerEvent(playerEvent); } else { reader.ReadSerializableInto(ref playerEvent); } } } else if (message.Tag == NetworkTags.EntityDeath) { ClientEntityManager.Instance.HandleEntityDeath(reader.ReadString()); } else if (message.Tag == NetworkTags.EntityDespawn) { ClientEntityManager.Instance.HandleEntityDespawn(reader.ReadString()); } else if (message.Tag == NetworkTags.PlayerEventEnd) { ClientEntityManager.Instance.HandlePlayerEventEnd(reader.ReadString()); } else if (message.Tag == NetworkTags.CapturePoint) { while (reader.Position < reader.Length) { CapturePoint capturePoint = ClientGameManager.Instance.CapturePoints[reader.ReadUInt16()]; reader.ReadSerializableInto(ref capturePoint); } } else if (message.Tag == NetworkTags.GameState) { ClientGameManager.Instance.UpdateGameState(reader.ReadSerializable <GameState>(), reader.ReadBoolean()); } } if (message.Tag == NetworkTags.ChatMessage) { UIManager.Instance.AddChatMessage(ClientGameManager.Instance.GameState.GetPlayer(reader.ReadString()), reader.ReadString()); } else if (message.Tag == NetworkTags.UnitList) { List <PlayerUnit> playerUnits = new List <PlayerUnit>(); while (reader.Position < reader.Length) { playerUnits.Add(reader.ReadSerializable <PlayerUnit>()); } UIManager.Instance.OnUnitListReceived(playerUnits); } else if (message.Tag == NetworkTags.PlayerJoined) { ClientGameManager.Instance.OnPlayerJoined(reader.ReadSerializable <Player>()); } else if (message.Tag == NetworkTags.PlayerLeft) { ClientGameManager.Instance.OnPlayerLeft(reader.ReadSerializable <Player>()); } } else if (OverallStateManager.Instance.OverallState != OverallState.IN_GAME) { if (waitingToJoin) { if (message.Tag == NetworkTags.GameState) { waitingToJoin = false; OverallStateManager.Instance.LoadGame(reader.ReadSerializable <GameState>(), reader.ReadBoolean()); } } else { if (message.Tag == NetworkTags.FullUnitList) { List <PlayerUnit> playerUnits = new List <PlayerUnit>(); while (reader.Position < reader.Length) { playerUnits.Add(reader.ReadSerializable <PlayerUnit>()); } MainMenuManager.Instance.OnUnitListReceived(playerUnits); } } } if (message.Tag == NetworkTags.Connection) { //Response to join request indicating if our matchmaking ticket was valid if (reader.ReadBoolean()) { IsConnectedToServer = true; //Notify anyone interested that we've completed joining a server Debug.Log("PlayFab: Ticket accepted by server, join completed."); ServerJoinSuccess?.Invoke("PlayFab: Ticket accepted by server, join completed."); } else { Debug.LogError("PlayFab: Ticket rejected by server, disconnecting."); ServerJoinFailure?.Invoke("PlayFab: Ticket rejected by server, disconnecting."); client.Disconnect(); } } } }