private void handleRequest(NetIncomingMessage im) { var packageType = (PacketType)im.ReadByte(); switch (packageType) { case PacketType.NewPlayer: Console.WriteLine("New player!"); var newPlayer = new NewPlayerPacketIO().ReadResponse(im); OnPlayerAdded?.Invoke(newPlayer.Player); break; case PacketType.AllPlayers: var data = new AllPlayersPacketIO().ReadResponse(im); foreach (var player in data.Players) { Players[player.Id] = player; } break; case PacketType.CreateProjectile: Console.WriteLine("projectile response"); var respo = new CreateProjectilePacketIO().ReadResponse(im); Console.WriteLine($"with id {respo.ProjectileData.Id}"); OnCreateProjectile?.Invoke(respo.ProjectileData); break; } }
private bool EstabilishConnection() { var time = DateTime.Now; NetIncomingMessage im; while (DateTime.Now.Subtract(time).Seconds < 5) { if ((im = _client.ReadMessage()) == null) { continue; } switch (im.MessageType) { case NetIncomingMessageType.VerboseDebugMessage: case NetIncomingMessageType.DebugMessage: case NetIncomingMessageType.WarningMessage: case NetIncomingMessageType.ErrorMessage: Console.WriteLine(im.ReadString()); break; case NetIncomingMessageType.StatusChanged: if (im.SenderConnection.Status == NetConnectionStatus.Connected) { Console.WriteLine("Connection accepted"); var hmsg = im.SenderConnection.RemoteHailMessage; var data = new LoginPacketIO().ReadResponse(hmsg); PlayerData = data.Player; Console.WriteLine($"Our id is '{PlayerData.Id}'"); foreach (var player in data.OtherPlayers) { Players[player.Id] = player; Console.WriteLine($"Already connected player with id {player.Id}"); OnPlayerAdded?.Invoke(Players[player.Id]); } OnConnected?.Invoke(PlayerData); Active = true; return(true); } break; case NetIncomingMessageType.ConnectionApproval: Console.WriteLine($"Connection approval: {im.ReadString()}"); break; default: Console.WriteLine($"not handled: {im.MessageType} | {(PacketType)im.ReadByte()}"); break; } } return(false); }
/// <summary> /// Adds a new player to alliance. /// Fires a new player added event. /// </summary> /// <param name="player">Player to add.</param> public void AddPlayer(Player player) { Players.Add(player); if (OnPlayerAdded != null) { OnPlayerAdded.Invoke(player); } }
public static void Add(Player player) { if (IsInputDeviceAlreadyRegistered(player.Input.GetInputDevice())) { Debug.LogWarning("Cannot add player: " + player + " because input device: " + player.Input.GetInputDevice() + " is already registered!"); return; } players_.Add(player); OnPlayerAdded.Invoke(player); }
private void OnUpdateTicked(object sender, UpdateTickedEventArgs e) { var currentLength = Game1.otherFarmers.Count; if (currentLength > _prevLength) { _monitor.VerboseLog("Player added"); OnPlayerAdded?.Invoke(); _prevLength = currentLength; } else if (currentLength < _prevLength) { _monitor.VerboseLog("Player removed"); OnPlayerRemoved?.Invoke(); _prevLength = currentLength; } }
/// <summary> /// Add a player to this ghost role. Invokes <see cref="OnPlayerAdded"/> and, in addition, /// possibly <see cref="OnMinPlayersReached"/>, <see cref="OnMaxPlayersReached"/>. /// Intended for use with <see cref="GhostRoleManager"/>. /// </summary> public void AddPlayer(ConnectedPlayer player) { WaitingPlayers.Add(player); totalPlayers++; OnPlayerAdded?.Invoke(player); if (totalPlayers == MinPlayers) { OnMinPlayersReached?.Invoke(); } if (totalPlayers == MaxPlayers) { OnMaxPlayersReached?.Invoke(); TimeRemaining = -2; // this ghost role is full; kill it } }
private void CheckSurroundingCells(out List <Player> newPlayers, out List <Food> newFood) { newPlayers = new List <Player>(); newFood = new List <Food>(); for (int i = 0; i < SurroundingCells.Count; i++) { for (int j = 0; j < SurroundingCells[i].ContainedPlayers.Count; j++) { Player player = SurroundingCells[i].ContainedPlayers[j]; if (PlayerIsIn(player)) { newPlayers.Add(player); OnPlayerAdded?.Invoke(this, new PlayerAddedEventArgs(ContainedPlayers, ContainedFood, player.Id)); } } } }
public Player AddPlayer(int id) { var retVal = new Player(id); var side = LeftPlayers.Count <= RightPlayers.Count ? CanoeSide.Left : CanoeSide.Right; (side == CanoeSide.Left ? LeftPlayers : RightPlayers).Add(retVal); retVal.OnRow += (timeStamp, backward) => { var listCount = side == CanoeSide.Left ? LeftPlayers.Count : RightPlayers.Count; _rowEntries.AddLast(new RowEntry { Player = retVal, Side = side, Timestamp = timeStamp, Value = (backward ? -1f : 1f) / listCount }); }; OnPlayerAdded?.Invoke(side, (side == CanoeSide.Left ? LeftPlayers.Count : RightPlayers.Count) - 1, retVal); return(retVal); }
/// <summary> /// Registers a new player to this dict. /// </summary> /// <param name="player">The player to be added.</param> public void Register(Player player) { Players.Add(player); OnPlayerAdded?.Invoke(player); }
/// <summary> /// Добавить игрока /// </summary> /// <param name="parNewPlayer">Данные о новом игроке</param> public void AddPlayer(MPlayer parNewPlayer) { _players.Add(parNewPlayer); OnPlayerAdded?.Invoke(parNewPlayer); }