private void OnClientSpawn(ClientSpawn clientSpawn, NetPeer peer) { if (_gameMode == GameMode.Royale) { return; } if (!_waitingPlayers.TryGetValue(peer.GetUId(), out var clientData)) { Logger.Log($"SERVER unknown peer spawn {peer.GetUId()}"); _server.DisconnectPeer(peer); } var player = new Player(clientData.UserId, peer.GetUId(), clientData.Name, clientData.DoubleUnits, _config) { UnitSkins = clientData.UnitSkins }; _players.Add(peer.GetUId(), player); if (_players.Count == 1) { StartGame(); } else { _world.AddPlayer(player); } SendPlayersInfo(); }
private void OnClientInput(ClientInput input, NetPeer peer) { _world.SetInput(peer.GetUId(), new ClientInput() { MaxX = input.MaxX, MaxY = input.MaxY, MinX = input.MinX, MinY = input.MinY, MoveX = input.MoveX, MoveY = input.MoveY, Rise = input.Rise, ViewRange = input.ViewRange }); }
public async void OnPeerDisconnected(NetPeer peer, DisconnectInfo disconnectInfo) { Logger.Log($"SERVER client {peer.GetUId()} disconnected, reason: '{disconnectInfo.Reason}'"); _peers.Remove(peer.GetUId()); if (_serverState == ServerState.Playing) { _world.RemovePlayer(peer.GetUId()); } else if (_players.ContainsKey(peer.GetUId())) { _players.Remove(peer.GetUId()); SendPlayersInfo(); } //Send info to master await SendInfoToMaster(); if (_peers.Count == 0) { Stop("no players"); } GC.Collect(); }
private async void OnClientConnection(ClientConnection clientConnection, NetPeer peer) { GC.Collect(); //check game state if (_gameMode == GameMode.Royale && (_serverState == ServerState.Playing || _serverState == ServerState.EndGame)) { Logger.Log($"SERVER connection attempt during game: {clientConnection.UserId}"); _server.DisconnectPeer(peer); return; } //check player var clientData = await _masterClient.RequestClientInfo(clientConnection.UserId, clientConnection.UserKey); if (!clientData.Valid) { Logger.Log($"SERVER invalid connection attempt: {clientConnection.UserId}", true); _server.DisconnectPeer(peer); return; } //add player to wait list if (_gameMode == GameMode.Free) { _waitingPlayers.Add(peer.GetUId(), clientData); } //create player for royale if (_gameMode == GameMode.Royale) { var player = new Player(clientData.UserId, peer.GetUId(), clientData.Name, clientData.DoubleUnits, _config) { UnitSkins = clientData.UnitSkins }; _players.Add(peer.GetUId(), player); if (_players.Count == 1) { _waitTime = _config.PlayerWaitTime; _serverState = ServerState.WaitingPlayers; } } //send map peer.Send(_netSerializer.Serialize(_world.GetServerMap()), SendOptions.ReliableUnordered); //add time if (_waitTime < _config.MinWaitTime) { _waitTime = _config.MinWaitTime; } //min time if last player if (_players.Count >= _config.MaxPlayers && _waitTime > _config.MinWaitTime) { _waitTime = _config.MinWaitTime; } //send player info Logger.Log($"SERVER player '{clientData.Name}' connected"); SendPlayersInfo(); //Send info to master await SendInfoToMaster(); }
public void OnPeerConnected(NetPeer peer) //Just add peer and wait for auth packet { Logger.Log($"SERVER client {peer.GetUId()} connected"); _peers.Add(peer.GetUId(), peer); }
private void OnClentLeave(ClientLeave leave, NetPeer peer) { _world.RemovePlayer(peer.GetUId(), false); }