private async Task ProcessPacketAsync(PlayerPacket packet) { if (_readyPacket is null && !(packet is ReadyPacket)) { LogHandler <WsClient> .Log.Error($"{packet.GuildId} guild didn't send a ReadyPayload."); return; } _readyPacket = packet as ReadyPacket; var vClient = new WsVoiceClient(_socket, packet.GuildId); VoiceClients.TryAdd(packet.GuildId, vClient); LogHandler <WsClient> .Log.Debug($"{packet.GuildId} client and engine has been initialized."); var voiceClient = VoiceClients[packet.GuildId]; switch (packet) { case PlayPacket play: await voiceClient.Engine.PlayAsync(play) .ConfigureAwait(false); break; case PausePacket pause: voiceClient.Engine.Pause(pause); break; case StopPacket stop: await voiceClient.Engine.StopAsync(stop) .ConfigureAwait(false); break; case DestroyPacket destroy: await voiceClient.Engine.DisposeAsync() .ConfigureAwait(false); break; case SeekPacket seek: voiceClient.Engine.Seek(seek); break; case EqualizerPacket equalizer: voiceClient.Engine.EqualizeStream(equalizer); break; case VolumePacket volume: voiceClient.Engine.SetVolume(volume); break; case VoiceUpdatePacket voiceUpdate: await VoiceClients[packet.GuildId].HandleVoiceUpdateAsync(voiceUpdate) .ConfigureAwait(false); break; } }
public static void SendPlayerPacket(PlayerPacket playerInfo) { var message = playerInfo.Serialize().Trim(); byte[] bytes = Encoding.UTF8.GetBytes(message); SendToAllInLobby(bytes); }
private void RecievePlayerPackets() { byte[] bytes = ReadData(sizeof(int), _networkStream); int numClients = BitConverter.ToInt32(bytes, 0); _playerPackets.Clear(); for (int i = 0; i < numClients; i++) { bytes = ReadData(sizeof(int), _networkStream); int packetSize = BitConverter.ToInt32(bytes, 0); bytes = ReadData(packetSize, _networkStream); PlayerPacket packet = PlayerPacket.FromBytes(bytes); if (_playerPackets.ContainsKey(packet.PlayerID)) { _playerPackets[packet.PlayerID] = packet; } else { _playerPackets.Add(packet.PlayerID, packet); } } MapComponent.Instance.SetPlayers(_playerPackets); }
public void SetPlayerPacket(PlayerPacket playerPacket) { _mapPlayer.SetPlayerPacket(playerPacket); SetSpriteID(playerPacket.SpriteID); SetRealPosition(); SetYFrame((int)playerPacket.Direction); }
public override void Render(FrameEventArgs e) { if (!_mapEvent.Enabled) { return; } PlayerPacket localPacket = MapComponent.Instance.GetLocalPlayerPacket(); if (localPacket == null || !(localPacket.PositionX == _mapEvent.MapX && localPacket.PositionY == _mapEvent.MapY) || _mapEvent.Priority == RenderPriority.OnTop) { base.Render(e); Renderer.PushStencilDepth(OpenTK.Graphics.OpenGL.StencilOp.Keep, OpenTK.Graphics.OpenGL.StencilFunction.Less); Renderer.PushWorldMatrix(); Renderer.SetFlipUV(false, true); Renderer.TranslateWorld(0, GetFrameHeight(), 0); OpenTK.Graphics.Color4 prevColor = GetColour(); OpenTK.Graphics.Color4 color = prevColor; color.A = 0.2f; SetColour(color); base.Render(e); SetColour(prevColor); Renderer.SetFlipUV(false, false); Renderer.PopWorldMatrix(); Renderer.PopStencilDepth(); } }
//Send everyone the closest disimilar data packet private void sendAllUpdates() { foreach (KeyValuePair <int, NetworkConnection> connection in _active_players) { //lock this part PlayerPacket closestPacket = null; //double min_dist = foreach (KeyValuePair <int, PlayerPacket> datum in _recentData) { if (datum.Key != connection.Key) { PlayerPacket temp = datum.Value; if (closestPacket == null) { closestPacket = temp; } else if (distance(_recentData[connection.Key], datum.Value) < distance(_recentData[connection.Key], closestPacket)) { closestPacket = temp; } } } //Send out closest different type if (closestPacket != null) { NetworkServer.SendToClient(connection.Key, 666, closestPacket); } } }
void Update() { uint size; try { while (SteamNetworking.IsP2PPacketAvailable(out size)) { var buffer = new byte[size]; uint bytesRead; CSteamID remoteId; if (SteamNetworking.ReadP2PPacket(buffer, size, out bytesRead, out remoteId)) { var message = Encoding.UTF8.GetString(buffer).Replace(" ", ""); PlayerPacket info = new PlayerPacket(message); if (info.playerId != SteamAPI.GetUserID() && SteamAPI.getLobbyID().m_SteamID != 0) { UpsertPlayer(info); } } } } catch (Exception e) { Logger.Error(e); } }
public void OnPlayerJoinEvent(PlayerJoinEvent ev) { var chunk = ev.Player.GetChunk(); chunk.PlayersInChunk.Add(ev.Player); var player = ev.Player; var nearPlayers = player.GetPlayersNear(); var packet = new PlayerPacket() { Name = player.Login, X = player.X, Y = player.Y, UserId = player.UserId, Speed = player.speed, SpriteIndex = player.SpriteIndex }; foreach (var nearPlayer in nearPlayers) { Log.Info("SENDING TO " + nearPlayer.X); nearPlayer.Tcp.Send(packet); var otherPlayerPacket = new PlayerPacket() { Name = nearPlayer.Login, X = nearPlayer.X, Y = nearPlayer.Y, UserId = nearPlayer.UserId, Speed = nearPlayer.speed, SpriteIndex = nearPlayer.SpriteIndex }; player.Tcp.Send(otherPlayerPacket); } }
public static void ReadPacket(ref NetIncomingMessage msg, ref PlayerPacket packet) { packet.name = msg.ReadString(); packet.uid = msg.ReadInt64(); packet.PosX = msg.ReadInt32(); packet.PosY = msg.ReadInt32(); packet.facingDirection = (Player.FacingDirections)msg.ReadInt32(); }
public static void WritePacket(ref NetOutgoingMessage msg, PlayerPacket packet) { msg.Write(packet.name); msg.Write(packet.uid); msg.Write(packet.PosX); msg.Write(packet.PosY); msg.Write((Int32)packet.facingDirection); }
public void readySession(NetworkMessage p_msg) { PlayerPacket newPacket = p_msg.ReadMessage <PlayerPacket>(); //Register for game data _client.RegisterHandler(666, gameSession); _client.Send(MsgType.Ready, newPacket); Debug.Log("Sent Ready Confirmation: " + newPacket._id); }
public override int OnReceive(ArraySegment <byte> buffer, int ByteTransferred) { PlayerPacket packet = new PlayerPacket(); packet.Des(buffer); Console.WriteLine($"[From Server] : {packet.message}"); return(buffer.Count); }
public MapPlayer RetrievePlayerQuery(int playerID) { PlayerPacket packet = null; BankData bankData = null; try { SqlCommand cmd = new SqlCommand("SELECT * FROM Players WHERE PlayerID='" + playerID + "'", _sqlConnection); SqlDataReader rdr = cmd.ExecuteReader(); if (rdr.Read()) { packet = new PlayerPacket(); bankData = new BankData(); packet.PlayerID = Convert.ToInt32(rdr["PlayerID"]); packet.Username = (string)rdr["Username"]; packet.MapID = Convert.ToInt32(rdr["MapID"]); packet.SpriteID = Convert.ToInt32(rdr["SpriteID"]); packet.Direction = (FacingDirection)(Convert.ToInt32(rdr["Direction"])); packet.PositionX = Convert.ToInt32(rdr["MapX"]); packet.PositionY = Convert.ToInt32(rdr["MapY"]); packet.PrevMapX = packet.PositionX; packet.PrevMapY = packet.PositionY; packet.RealX = packet.PositionX * 32; packet.RealY = packet.PositionY * 32; packet.OnBridge = Convert.ToInt32(rdr["OnBridge"]) == 1 ? true : false; packet.Data = new PlayerData(); packet.Data.Level = Convert.ToInt32(rdr["Level"]); packet.Data.Experience = Convert.ToInt32(rdr["Experience"]); packet.Data.SetClassID(Convert.ToInt32(rdr["ClassID"])); packet.Data.HP = Convert.ToInt32(rdr["HP"]); packet.Data.MP = Convert.ToInt32(rdr["MP"]); packet.Data.Stamina = Convert.ToInt32(rdr["Stamina"]); packet.Data.Gold = Convert.ToInt32(rdr["Gold"]); packet.Data.ParseInventoryString((string)rdr["Inventory"]); packet.Data.ParseEquipmentString((string)rdr["Equipment"]); bankData.ParseBankString((string)rdr["Bank"]); packet.Data.ParseQuestsString((string)rdr["Quests"]); packet.Data.InvestedStats.Vitality = Convert.ToInt32(rdr["VitalityPoints"]); packet.Data.InvestedStats.Inteligence = Convert.ToInt32(rdr["InteligencePoints"]); packet.Data.InvestedStats.Strength = Convert.ToInt32(rdr["StrengthPoints"]); packet.Data.InvestedStats.Agility = Convert.ToInt32(rdr["AgilityPoints"]); packet.Data.InvestedStats.MeleeDefence = Convert.ToInt32(rdr["MeleeDefencePoints"]); packet.Data.InvestedStats.RangeDefence = Convert.ToInt32(rdr["RangeDefencePoints"]); packet.Data.InvestedStats.MagicDefence = Convert.ToInt32(rdr["MagicDefencePoints"]); } rdr.Close(); } catch (Exception e) { Console.WriteLine(e.Message); Console.WriteLine(e.StackTrace); } return(new MapPlayer(packet, bankData)); }
void INotificationService.ToPlayer(Player player, PlayerMessages messages) { var packet = new PlayerPacket(messages); // Transmit to all user's connected clients foreach (var clientId in player.ClientIds) { Clients[clientId].receive(packet); } }
public static void ReadPacket(ref NetIncomingMessage msg, ref WorldPacket packet) { packet.playerCount = msg.ReadInt32(); for (int i = 0; i < packet.playerCount; i++) { PlayerPacket p = new PlayerPacket(); ReadPacket(ref msg, ref p); packet.playerPackets.Add(p); } }
public override void Render(FrameEventArgs e) { if (_mapEnemy.Dead) { return; } PlayerPacket localPacket = MapComponent.Instance.GetLocalPlayerPacket(); if (localPacket == null || !(localPacket.PositionX == _mapEnemy.MapX && localPacket.PositionY == _mapEnemy.MapY)) { base.Render(e); EnemyData data = _mapEnemy.GetEnemyData(); Vector3 pos = Transform.Position; pos.Y -= GetFrameHeight() + Renderer.GetFont().GetTextHeight(data.Name); pos.X -= Renderer.GetFont().GetTextWidth(data.Name) / 2; OpenTK.Graphics.Color4 colour = OpenTK.Graphics.Color4.Red; //Renderer.DisableDepthTest(); Renderer.PrintText(data.Name, ref pos, ref colour); int nameHeight = Renderer.GetFont().GetTextHeight(data.Name); Vector3 size = new Vector3(GetFrameWidth(), 9, 1); pos.X = Transform.Position.X - (GetFrameWidth() / 2); pos.Y += nameHeight + 5; colour = OpenTK.Graphics.Color4.Black; Renderer.FillShape(ShapeFactory.Rectangle, ref pos, ref size, ref colour); pos.X += 2; pos.Y += 2; size.Y = 5; size.X = (GetFrameWidth() - 4) * ((float)_mapEnemy.HP / _mapEnemy.MaxHP); colour = OpenTK.Graphics.Color4.Red; Renderer.FillShape(ShapeFactory.Rectangle, ref pos, ref size, ref colour); //Renderer.EnableDepthTest(); Renderer.PushStencilDepth(OpenTK.Graphics.OpenGL.StencilOp.Keep, OpenTK.Graphics.OpenGL.StencilFunction.Less); Renderer.PushWorldMatrix(); Renderer.SetFlipUV(false, true); Renderer.TranslateWorld(0, GetFrameHeight(), 0); OpenTK.Graphics.Color4 prevColor = GetColour(); OpenTK.Graphics.Color4 color = prevColor; color.A = 0.2f; SetColour(color); base.Render(e); SetColour(prevColor); Renderer.SetFlipUV(false, false); Renderer.PopWorldMatrix(); Renderer.PopStencilDepth(); } }
PlayerPacket formatPacket(int p_id, char p_type, double p_x, double p_y, double p_z) { PlayerPacket outMsg = new PlayerPacket(); outMsg._id = p_id; outMsg._playerType = p_type; outMsg._x = p_x; outMsg._y = p_y; outMsg._z = p_z; return(outMsg); }
public void Awake() { if (Instance != this) { Instance = this; DontDestroyOnLoad(gameObject); _playerInfo = new PlayerPacket(SteamAPI.GetUserName(), SteamAPI.GetUserID()); _currentScene = SceneManager.GetActiveScene().name; } }
public static void ReadPlayer(Client client, PacketReader reader) { PlayerPacket pp = new PlayerPacket(); pp.Read(reader); if (!reader.Failed) { Client.HandlePacketPlayer(client, pp); } }
public void UpdateTransform(PlayerPacket packet) { username = packet.Username; position.x = packet.PosX; position.y = packet.PosY; position.z = packet.PosZ; rotation.x = packet.RotX; rotation.y = packet.RotY; rotation.z = packet.RotZ; destroyTimer = 0f; }
void INotificationService.ToPlayers(IEnumerable <Player> players, PlayerMessages messages) { var packet = new PlayerPacket(messages); foreach (var player in players) { foreach (var clientId in player.ClientIds) { Clients[clientId].receive(packet); } } }
public Dictionary <string, float> GetConnectedPlayerDownloadStatus() { Dictionary <string, float> connectedPlayerStatus = new Dictionary <string, float>(); connectedPlayerStatus.Add(_playerInfo.playerName, _playerInfo.Ready ? 1f : _playerInfo.playerProgress); for (int i = 0; i < _connectedPlayers.Count; i++) { PlayerPacket info = _connectedPlayers.Values.ToArray()[i]; connectedPlayerStatus.Add(info.playerName, info.Ready ? 1f : info.playerProgress); } return(connectedPlayerStatus); }
//Listens for player confirmation public void registerPlayer(NetworkMessage p_msg) { PlayerPacket newPacket = p_msg.ReadMessage <PlayerPacket>(); Debug.Log("Received this: " + newPacket._id); //should lock this for safety if (!_healthy_players.ContainsKey(newPacket._id) && _active_players.ContainsKey(newPacket._id)) { _healthy_players.Add(newPacket._id, _active_players [newPacket._id]); _recentData.Add(newPacket._id, newPacket); } Debug.Log("Registered a participant"); }
public void UpdatePosistion(PlayerPacket packet) { transform.position = new Vector3(packet.posX, packet.posY, packet.posZ); transform.rotation = Quaternion.Euler(new Vector3(packet.rotX, packet.rotY, packet.rotZ)); if (packet.fire) { fire(packet.shotP); } else if (packet.loading) { load(packet.shotP); } }
public void playerUpdate(NetworkMessage p_msg) { PlayerPacket newPacket = p_msg.ReadMessage <PlayerPacket>(); if (_recentData.ContainsKey(newPacket._id)) { _recentData.Add(newPacket._id, newPacket); } //assume instant response //PlayerPacket outMsg; //outMsg. }
private void OnPlayerCommandReceived(PlayerPacket playerPacket) { Debug.Log($"Player Command: {playerPacket.PlayerCommand} Received"); switch (playerPacket.PlayerCommand) { case PlayerCommand.CHANGE_PLAYER_NAME: _runtimeManager.Player.ChangePlayerName(playerPacket.PlayerName, playerPacket.PlayerId); break; default: throw new ArgumentOutOfRangeException(); } }
public override void OnRecvPacket(ArraySegment <byte> buffer) { if (buffer.Count == 0) { return; } PlayerPacket packet = new PlayerPacket(); packet.Des(buffer); packet.message += " " + SessionID + "번째 그루트"; Console.WriteLine($"[From Client message] : {packet.message}"); }
public void OnPlayerAppears(PlayerPacket packet) { // instantiate the player if needed PlayerHandler.BuildAndInstantiate(new PlayerFactoryOptions() { SpriteIndex = packet.SpriteIndex, UserId = packet.UserId, Speed = packet.Speed, tileX = packet.X, tileY = packet.Y, IsMainPlayer = packet.UserId == UnityClient.Player.UserId }); TouchHandler.GameTouchOn = true; }
protected override void RenderContent() { base.RenderContent(); PlayerPacket playerPacket = MapComponent.Instance.GetLocalPlayerPacket(); if (playerPacket != null) { int width = GetContentWidth() / 3; int x = (GetContentWidth() / 2) - 16; int y = 0; Vector3 size = new Vector3(32, 32, 1); for (int i = 0; i < 9; i++) { y = 10 + (i * 42); int equipmentID = playerPacket.Data.GetEquipedItemID((EquipmentSlot)i); ItemData data = ItemData.GetItemData(equipmentID); if (data != null) { Vector3 pos = new Vector3(x, y, 0); Rectangle source = new Rectangle((data.IconID % 8) * 32, (data.IconID / 8) * 32, 32, 32); Texture texture = Assets.GetTexture("Icons/" + data.IconSheetImage); Color4 colour = Color4.White; Renderer.FillTexture(texture, ShapeFactory.Rectangle, ref pos, ref size, ref source, ref colour); } } Tuple <int, int> ammoInfo = playerPacket.Data.GetEquipedAmmo(); ItemData data2 = ItemData.GetItemData(ammoInfo.Item1); if (data2 != null) { y += 42; Vector3 pos = new Vector3(x, y, 0); Rectangle source = new Rectangle((data2.IconID % 8) * 32, (data2.IconID / 8) * 32, 32, 32); Texture texture = Assets.GetTexture("Icons/" + data2.IconSheetImage); Color4 colour = Color4.White; Renderer.FillTexture(texture, ShapeFactory.Rectangle, ref pos, ref size, ref source, ref colour); if (ammoInfo.Item2 > 1) { string text = ammoInfo.Item2.ToString(); pos.X += 32; colour = Color4.Red; Renderer.PrintText(text, ref pos, ref colour); } } } }
private void handleConnect() { //TODO: Input validation if (m.isServer) { m.server = new Server(data[(int)MMTextFieldSelected.IPAddress], Convert.ToInt32(data[(int)MMTextFieldSelected.Port]), m); } else { m.client = new Client(data[(int)MMTextFieldSelected.IPAddress], Convert.ToInt32(data[(int)MMTextFieldSelected.Port]), m); IPEndPoint localAddr = ClientSocketHandler.clientSocket.LocalEndPoint as IPEndPoint; PlayerPacket p = new PlayerPacket(localAddr, data[(int)MMTextFieldSelected.UserName], data[(int)MMTextFieldSelected.Password], PlayerStatus.Connecting, true, true); Client.ToSendPacket.Enqueue(new NetPacket(null, p)); } m.gameState = GameState.Map; }