/// <summary> /// Ticks the server, include the network, /// and all worlds (and all chunks within those [and all entities within those]). /// </summary> /// <param name="delta">The time between the last tick and this one</param> public static void Tick(double delta) { Delta = delta; GlobalTickTime += delta; try { NetworkBase.Tick(); } catch (Exception ex) { SysConsole.Output(OutputType.ERROR, "Error / networktick: " + ex.ToString()); } try { secondTracker += Delta; if (secondTracker >= 1.0) { secondTracker -= 1.0; OncePerSecondTick(); } } catch (Exception ex) { SysConsole.Output(OutputType.ERROR, "Error / oncepersecondtick: " + ex.ToString()); } try { ServerCommands.Tick(); ConsoleHandler.CheckInput(); } catch (Exception ex) { SysConsole.Output(OutputType.ERROR, "Error / command tick: " + ex.ToString()); } try { for (int i = 0; i < WaitingPlayers.Count; i++) { if (GlobalTickTime - WaitingPlayers[i].JoinTime > 10) { WaitingPlayers.RemoveAt(i); i--; } } for (int i = 0; i < Players.Count; i++) { // TODO: CVar if (GlobalTickTime - Players[i].LastPing > 60 || GlobalTickTime - Players[i].LastSecondaryPing > 60) { DespawnPlayer(Players[i]); i--; } } } catch (Exception ex) { SysConsole.Output(OutputType.ERROR, "Error / general tick: " + ex.ToString()); } }
public static void WelcomeReceived(int _fromClient, Packet _packet) { int _clientIdCheck = _packet.ReadInt(); string _username = _packet.ReadString(); Debug.Log($"{Server.clients[_fromClient].tcp.socket.Client.RemoteEndPoint} connected successfully and is now player {_fromClient}."); if (_fromClient != _clientIdCheck) { Debug.Log($"Player \"{_username}\" (ID: {_fromClient}) has assumed the wrong client ID ({_clientIdCheck})!"); } // Send all players to the new player foreach (Client _client in Server.clients.Values) { if (_client.player != null) { if (_client.id != _fromClient) { ServerSend.SpawnPlayer(_fromClient, _client.player); } } } if (RoundManager.instance.rState == RoundManager.RoundState.WAITING || RoundManager.instance.rState == RoundManager.RoundState.COUNTDOWN && RoundManager.instance.countdownCurrentTimer > (RoundManager.instance.countdownTime / 3)) { Server.clients[_fromClient].SendIntoGame(_username); } else { WaitingPlayers _player = new WaitingPlayers(); _player.id = _fromClient; _player.username = _username; RoundManager.instance.waitingPlayers.Add(_player); } }
public ActionResult GiveInfo(int respondToId = int.MinValue) { if (AgentState != AgentState.InGame) { logger.Warn("[Agent {id}] Requested give info, but not in game", Id); if (EndIfUnexpectedAction) { return(ActionResult.Finish); } } bool shouldRepeat = StartGameComponent.TeamMates.Contains(respondToId); if (!StartGameComponent.TeamMates.Contains(respondToId) && WaitingPlayers.Count > 0) { respondToId = WaitingPlayers[0]; WaitingPlayers.RemoveAt(0); logger.Debug("[Agent {id}] Sent exchange information response to first waiting player ({id2})", Id, respondToId); } if (!StartGameComponent.TeamMates.Contains(respondToId)) { logger.Warn("[Agent {id}] Requested give info, but has no target", Id); if (EndIfUnexpectedAction) { return(ActionResult.Finish); } else { return(MakeDecisionFromStrategy()); } } SetPenalty(ActionType.InformationExchange, shouldRepeat); SendMessage(MessageFactory.GetMessage(new ExchangeInformationResponse(respondToId, BoardLogicComponent.GetDistances(), BoardLogicComponent.GetRedTeamGoalAreaInformation(), BoardLogicComponent.GetBlueTeamGoalAreaInformation())), shouldRepeat); logger.Debug("[Agent {id}] Sent exchange information response to {id2} ", Id, respondToId); return(ActionResult.Continue); }
public void CancelCurrentMatch() { lock (WaitingPlayers) { this.Locker.WaitOne(); if (this.CurrentMatch == null) { if (WaitingPlayers.Count == 0) { this.Locker.Release(); return; } Console.WriteLine("Player " + this.ClientId + " is not waiting anymore"); Console.WriteLine(); WaitingPlayers.Dequeue(); } else { Console.WriteLine("Player " + this.ClientId + " has quit the match"); Console.WriteLine(); Player opponent = this.CurrentMatch.GetOpponent(this); opponent.Locker.WaitOne(); opponent.InvokeEndMatch(); opponent.CurrentMatch = null; opponent.Locker.Release(); this.InvokeEndMatch(); this.CurrentMatch = null; } this.Locker.Release(); } }
public void SeekMatch(string displayName) { lock (WaitingPlayers) { this.Locker.WaitOne(); if (this.CurrentMatch != null) { this.Locker.Release(); return; } this.DisplayName = displayName; while (WaitingPlayers.Count > 0) { Player waitingPlayer = WaitingPlayers.Peek(); waitingPlayer.Locker.WaitOne(); try { waitingPlayer.InvokeStartMatch(this.DisplayName, this.ClientId, false); } catch (Exception) { WaitingPlayers.Dequeue(); waitingPlayer.Locker.Release(); continue; } try { this.InvokeStartMatch(waitingPlayer.DisplayName, waitingPlayer.ClientId, true); } catch (Exception) { try { waitingPlayer.InvokeCancelMatch(); } catch (Exception) { WaitingPlayers.Dequeue(); } waitingPlayer.Locker.Release(); this.Locker.Release(); return; } WaitingPlayers.Dequeue(); this.CurrentMatch = GameMaster.NewMatch(waitingPlayer, this); this.Locker.Release(); waitingPlayer.CurrentMatch = this.CurrentMatch; waitingPlayer.Locker.Release(); Console.WriteLine("Game #" + CurrentMatch.Id + " has started between players " + waitingPlayer.ClientId + " and " + this.ClientId); Console.WriteLine(); return; } WaitingPlayers.Enqueue(this); this.Locker.Release(); } Console.WriteLine("Player " + this.ClientId + " is waiting for an opponent"); Console.WriteLine(); }