コード例 #1
0
ファイル: HandleDataUDP.cs プロジェクト: LanaFan/ElecyNetwork
        private static void HandleRotationUpdate(GamePlayerUDP player, byte[] data)
        {
            using (PacketBuffer buffer = new PacketBuffer())
            {
                buffer.WriteBytes(data);
                buffer.ReadInteger();
                ObjectType type        = (ObjectType)buffer.ReadInteger();
                int        index       = buffer.ReadInteger();
                int        UpdateIndex = buffer.ReadInteger();
                float[]    rot         = new float[4];
                switch (type)
                {
                case ObjectType.player:
                    rot[0] = buffer.ReadFloat();
                    rot[1] = buffer.ReadFloat();
                    rot[2] = buffer.ReadFloat();
                    rot[3] = buffer.ReadFloat();
                    player.room.roomPlayers[player.ID].rotation.SetUpdate(rot, UpdateIndex);
                    break;

                case ObjectType.spell:
                    rot[0] = buffer.ReadFloat();
                    rot[1] = buffer.ReadFloat();
                    rot[2] = buffer.ReadFloat();
                    rot[3] = buffer.ReadFloat();
                    try
                    {
                        player.room.dynamicObjectsList.Get(index).rotation.SetUpdate(rot, UpdateIndex);
                    }
                    catch (Exception ex)
                    {
                        if (ex is NullReferenceException || ex is IndexOutOfRangeException)
                        {
                            return;
                        }
                        Global.serverForm.Debug(ex + "");
                    }
                    break;

                case ObjectType.staticObjects:
                    rot[0] = buffer.ReadFloat();
                    rot[1] = buffer.ReadFloat();
                    rot[2] = buffer.ReadFloat();
                    rot[3] = buffer.ReadFloat();
                    try
                    {
                        player.room.staticObjectsList.Get(index).rotation.SetUpdate(rot, UpdateIndex);
                    }
                    catch (Exception ex)
                    {
                        if (ex is NullReferenceException || ex is IndexOutOfRangeException)
                        {
                            return;
                        }
                        Global.serverForm.Debug(ex + "");
                    }
                    break;
                }
            }
        }
コード例 #2
0
ファイル: ServerTCP.cs プロジェクト: LanaFan/ElecyNetwork
 public void EnterRoom(BaseGameRoom room, GamePlayerUDP playerUDP, int ID)
 {
     this.room      = room;
     this.playerUDP = playerUDP;
     this.ID        = ID;
     Global.unconectedPlayersUDP.Add(playerUDP);
 }
コード例 #3
0
ファイル: SendDataUDP.cs プロジェクト: LanaFan/ElecyNetwork
        /// <summary>
        /// Buffer:
        ///         int PacketNum;
        /// </summary>
        public static void SendConnectionOK(GamePlayerUDP player)
        {
            PacketBuffer buffer = new PacketBuffer();

            buffer.WriteInteger((int)UDPServerPackets.USConnectionOK);
            UDPConnector.Send(player, buffer.ToArray());
            buffer.Dispose();
        }
コード例 #4
0
ファイル: HandleDataUDP.cs プロジェクト: LanaFan/ElecyNetwork
 /// <summary>
 /// Buffer:
 ///         int PacketNum;
 ///         int player's ID (1 or 2);
 ///         int roomIndex;
 /// </summary>
 private static void HandleConnectionComplite(GamePlayerUDP player, byte[] data)
 {
     using (PacketBuffer buffer = new PacketBuffer())
     {
         buffer.WriteBytes(data);
         buffer.ReadInteger();
         player.Connected();
     }
 }
コード例 #5
0
ファイル: SystemUDP.cs プロジェクト: LanaFan/ElecyNetwork
 public static void Send(GamePlayerUDP player, byte[] data)
 {
     try
     {
         connectUDP.Send(data, data.Length, player.ip);
     }
     catch
     {
         //Close
     }
 }
コード例 #6
0
ファイル: HandleDataUDP.cs プロジェクト: LanaFan/ElecyNetwork
 public static void HandleNetworkInformation(GamePlayerUDP player, byte[] data)
 {
     using (PacketBuffer buffer = new PacketBuffer())
     {
         buffer.WriteBytes(data);
         int packetnum = buffer.ReadInteger();
         if (Packets.TryGetValue(packetnum, out Packet_ Packet))
         {
             Packet.Invoke(player, data);
         }
     }
 }
コード例 #7
0
ファイル: HandleDataUDP.cs プロジェクト: LanaFan/ElecyNetwork
        private static void HandleHealthUpdate(GamePlayerUDP player, byte[] data)
        {
            using (PacketBuffer buffer = new PacketBuffer())
            {
                buffer.WriteBytes(data);
                buffer.ReadInteger();
                ObjectType type        = (ObjectType)buffer.ReadInteger();
                int        index       = buffer.ReadInteger();
                int        UpdateIndex = buffer.ReadInteger();
                int        _health     = buffer.ReadInteger();
                switch (type)
                {
                case ObjectType.player:
                    player.room.roomPlayers[player.ID].healthPoints.SetUpdate(_health, UpdateIndex);
                    break;

                case ObjectType.spell:
                    try
                    {
                        player.room.dynamicObjectsList.Get(index).healthPoints.SetUpdate(_health, UpdateIndex);
                    }
                    catch (Exception ex)
                    {
                        if (ex is NullReferenceException || ex is IndexOutOfRangeException)
                        {
                            return;
                        }
                        Global.serverForm.Debug(ex + "");
                    }
                    break;

                case ObjectType.staticObjects:
                    try
                    {
                        player.room.staticObjectsList.Get(index).healthPoints.SetUpdate(_health, UpdateIndex);
                    }
                    catch (Exception ex)
                    {
                        if (ex is NullReferenceException || ex is IndexOutOfRangeException)
                        {
                            return;
                        }
                        Global.serverForm.Debug(ex + "");
                    }
                    break;
                }
            }
        }
コード例 #8
0
ファイル: HandleDataUDP.cs プロジェクト: LanaFan/ElecyNetwork
 private static void HandleSynergyStepBack(GamePlayerUDP player, byte[] data)
 {
     using (PacketBuffer buffer = new PacketBuffer())
     {
         buffer.WriteBytes(data);
         buffer.ReadInteger();
         ObjectType type          = (ObjectType)buffer.ReadInteger();
         int        index         = buffer.ReadInteger();
         int        StepBackIndex = buffer.ReadInteger();
         switch (type)
         {
         case ObjectType.player:
             player.room.roomPlayers[player.ID].synergyPoints.UdpateStepBack(StepBackIndex);
             break;
         }
     }
 }
コード例 #9
0
ファイル: HandleDataUDP.cs プロジェクト: LanaFan/ElecyNetwork
        private static void HandleRotationStepback(GamePlayerUDP player, byte[] data)
        {
            using (PacketBuffer buffer = new PacketBuffer())
            {
                buffer.WriteBytes(data);
                buffer.ReadInteger();
                ObjectType type          = (ObjectType)buffer.ReadInteger();
                int        index         = buffer.ReadInteger();
                int        StepBackIndex = buffer.ReadInteger();
                switch (type)
                {
                case ObjectType.spell:
                    try
                    {
                        player.room.dynamicObjectsList.Get(index).rotation.UdpateStepBack(StepBackIndex);
                    }
                    catch (Exception ex)
                    {
                        if (ex is NullReferenceException || ex is IndexOutOfRangeException)
                        {
                            return;
                        }
                        Global.serverForm.Debug(ex + "");
                    }
                    break;

                case ObjectType.staticObjects:
                    try
                    {
                        player.room.staticObjectsList.Get(index).rotation.UdpateStepBack(StepBackIndex);
                    }
                    catch (Exception ex)
                    {
                        if (ex is NullReferenceException || ex is IndexOutOfRangeException)
                        {
                            return;
                        }
                        Global.serverForm.Debug(ex + "");
                    }
                    break;
                }
            }
        }
コード例 #10
0
ファイル: BaseGameRoom.cs プロジェクト: LanaFan/ElecyNetwork
        public BaseGameRoom(ClientTCP client, int playersCount, int mapIndex = 0)
        {
            // Total number of players that can be in one room
            PlayersCount = playersCount;

            expectant = new object();

            RoomType();

            // Create lists of Players (TCP, UDP and struct contains player's game parameters)
            playersTCP  = new ClientTCP[playersCount];
            playersUDP  = new GamePlayerUDP[playersCount];
            roomPlayers = new RoomPlayer[playersCount];

            //Create list of dynamic objects
            dynamicObjectsList = new DynamicObjectList(this);

            //Create list of static objects
            staticObjectsList = new StaticObjectList();

            //Randomize mapIndex if it's not specified
            _mapIndex = mapIndex == 0 ? new Random().Next(1, Constants.MAPS_COUNT) : mapIndex;

            //Default room status
            Status = RoomState.Searching;

            // Load indicators
            _loadedTCP = new bool[playersCount];
            _loadedUDP = new bool[playersCount];

            // Get Map
            map = Global.data.GetMap(_mapIndex);

            //Create randomizer
            randomer = new ArenaRandomGenerator(map);

            // Adds player to the room
            AddPlayer(client);
        }
コード例 #11
0
ファイル: BaseGameRoom.cs プロジェクト: LanaFan/ElecyNetwork
        public bool AddPlayer(ClientTCP client)
        {
            lock (expectant)
            {
                for (int i = 0; i < PlayersCount; i++)
                {
                    if (playersTCP[i] == null)
                    {
                        playersTCP[i] = client;
                        client.EnterRoom(this, playersUDP[i] = new GamePlayerUDP(client.ip, i, this), i);
                        roomPlayers[i] = new RoomPlayer(
                            i,
                            ObjectType.player,
                            1000,
                            1000,
                            new float[] {
                            map.SpawnPoints.ToArray()[i].PositionX,
                            0.5f,
                            map.SpawnPoints.ToArray()[i].PositionY,
                        },
                            new float[] {
                            map.SpawnPoints.ToArray()[i].RotationX,
                            map.SpawnPoints.ToArray()[i].RotationY,
                            map.SpawnPoints.ToArray()[i].RotationZ,
                            map.SpawnPoints.ToArray()[i].RotationW
                        }
                            );                             // You can create it when player starts queue using params from database

                        if (PlayersCount == playersTCP.Count(c => c != null))
                        {
                            StartLoad();
                        }
                        return(true);
                    }
                }
                return(false);
            }
        }