예제 #1
0
        /// <summary>
        ///             Buffer:
        ///                     int PacketNum;
        ///                     string race;
        ///                     int spellCount;
        ///                     short[spellCount] spellIndex
        /// </summary>
        private static void HandleSaveSkillBuild(ClientTCP client, byte[] data)
        {
            PacketBuffer buffer = new PacketBuffer();

            buffer.WriteBytes(data);
            buffer.ReadInteger();
            string race       = buffer.ReadString();
            int    spellCount = buffer.ReadInteger();

            string[] spellBuild = new string[spellCount];
            for (int i = 0; i < spellCount; i++)
            {
                string spellIndex = "" + buffer.ReadShort();
                while (spellIndex.Length != 4)
                {
                    spellIndex = "0" + spellIndex;
                }
                string spellType = "" + buffer.ReadShort();
                while (spellType.Length != 4)
                {
                    spellType = "0" + spellType;
                }
                spellBuild[i] = spellIndex + "" + spellType;
            }
            buffer.Dispose();
            //Global.data.SetSkillBuildData(client.nickname, race, spellBuild);
            SendDataTCP.SendBuildSaved(client);
        }
예제 #2
0
 /// <summary>
 ///             Buffer:
 ///                     int PacketNum;
 /// </summary>
 private static void HandleQueueStop(ClientTCP client, byte[] data)
 {
     Queue.StopSearch(client);
     foreach (ClientTCP friend in client.friends)
     {
         SendDataTCP.SendFriendChange(client, friend);
     }
 }
예제 #3
0
        /// <summary>
        ///             Buffer:
        ///                     int PacketNum;
        ///                     string message;
        /// </summary>
        private static void HandleGlChatMsg(ClientTCP client, byte[] data)
        {
            PacketBuffer buffer = new PacketBuffer();

            buffer.WriteBytes(data);
            buffer.ReadInteger();
            SendDataTCP.SendGlChatMsg(client.nickname, buffer.ReadString() /* message */);
            buffer.Dispose();
        }
예제 #4
0
 public void LoadSpells(ClientTCP client)
 {
     short[][] spellBuilds = new short[PlayersCount][];
     for (int i = 0; i < PlayersCount; i++)
     {
         spellBuilds[i] = playersTCP[i].accountData.AccountSkillBuilds.IgnisBuild.ToArray();
     }
     SendDataTCP.SendLoadSpells(client, spellBuilds);
 }
예제 #5
0
 private void StartLoad()
 {
     Status = RoomState.Loading;
     foreach (ClientTCP player in playersTCP)
     {
         player.clientState = ClientTCPState.GameRoom;
         player.playerState = NetPlayerState.Playing;
     }
     SendDataTCP.SendMatchFound(this);
 }
예제 #6
0
 public void Surrended(ClientTCP client)
 {
     CloseUpdateTimer();
     Status = RoomState.MatchEnded;
     foreach (ClientTCP player in playersTCP)
     {
         player.playerState = NetPlayerState.EndPlaying;
     }
     _closeTimer = new Timer(EndGameSession, null, 300000, Timeout.Infinite);
     SendDataTCP.SendMatchEnded(client.nickname, this);
 }
예제 #7
0
 private static void AcceptCallback(IAsyncResult ar)
 {
     if (!Closed)
     {
         Socket socket = _serverSocket.EndAccept(ar);
         _serverSocket.BeginAccept(new AsyncCallback(AcceptCallback), null);
         ClientTCP client = new ClientTCP(socket, socket.RemoteEndPoint as IPEndPoint);
         Global.clientList.Add(client);
         SendDataTCP.SendClientConnetionOK(client);
     }
 }
예제 #8
0
        /// <summary>
        ///             Buffer:
        ///                     int PacketNum;
        ///                     string race;
        /// </summary>
        private static void HandleGetSkillBuild(ClientTCP client, byte[] data)
        {
            PacketBuffer buffer = new PacketBuffer();

            buffer.WriteBytes(data);
            buffer.ReadInteger();
            string race = buffer.ReadString();

            buffer.Dispose();
            short[] skillBuild = client.accountData.AccountSkillBuilds.IgnisBuild.ToArray();
            SendDataTCP.SendSkillBuild(client, skillBuild, race);
        }
예제 #9
0
 public void SpawnTree(ClientTCP client, int treeCount, bool bigTree, bool mediumTree, bool smallTree)
 {
     int[] ranges;
     lock (expectant)
     {
         if (!staticObjectsList.GetRange(StaticTypes.tree, out ranges))
         {
             ranges = staticObjectsList.Add(StaticTypes.tree, ObjectType.staticObjects, this, treeCount, bigTree, mediumTree, smallTree);
         }
     }
     SendDataTCP.SendTreeSpawned(client, ranges);
 }
예제 #10
0
 public void SpawnRock(ClientTCP client, int rockCount, bool bigRock, bool mediumRock, bool smallRock)
 {
     int[] ranges;
     lock (expectant)
     {
         if (!staticObjectsList.GetRange(StaticTypes.rock, out ranges))
         {
             ranges = staticObjectsList.Add(StaticTypes.rock, ObjectType.staticObjects, this, rockCount, bigRock, mediumRock, smallRock);
         }
     }
     SendDataTCP.SendRockSpawned(client, ranges);
 }
예제 #11
0
 private void EndGameSession(Object o)
 {
     _closeTimer.Dispose();
     for (int i = 0; i < PlayersCount; i++)
     {
         if (playersTCP[i] != null)
         {
             SendDataTCP.SendRoomLogOut(playersTCP[i]);
             DeletePlayer(playersTCP[i]);
         }
     }
 }
예제 #12
0
        /// <summary>
        ///             Buffer:
        ///                     int PacketNum;
        ///                     int matchType;
        ///                     string race;
        /// </summary>
        private static void HandleQueueStart(ClientTCP client, byte[] data)
        {
            PacketBuffer buffer = new PacketBuffer();

            buffer.WriteBytes(data);
            buffer.ReadInteger();
            Queue.StartSearch(client, buffer.ReadInteger(), buffer.ReadString());
            foreach (ClientTCP friend in client.friends)
            {
                SendDataTCP.SendFriendChange(client, friend);
            }
            buffer.Dispose();
        }
예제 #13
0
        private void txtChat_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyValue.Equals(13))
            {
                if (!ServerTCP.Closed)
                {
                    if (!String.IsNullOrEmpty(txtChat.Text))
                    {
                        if (txtChat.Text.StartsWith("/"))
                        {
                            string[] commands = txtChat.Text.Split(' ');
                            switch (commands[0])
                            {
                            case "/AddAccount":
                                if (commands.Length == 4)
                                {
                                    Global.data.AddAccount(commands[1], commands[2], commands[3]);
                                }
                                else
                                {
                                    Global.serverForm.Debug("Invalid arguments in command: " + commands[0]);
                                }
                                break;

                            case "/AddMap":
                                if (commands.Length == 16)
                                {
                                    Global.data.AddMap(int.Parse(commands[1]), int.Parse(commands[2]), int.Parse(commands[3]), new float[] { float.Parse(commands[4]), float.Parse(commands[5]) }, new float[] { float.Parse(commands[6]), float.Parse(commands[7]) }, new float[] { float.Parse(commands[8]), float.Parse(commands[9]), float.Parse(commands[10]), float.Parse(commands[11]) }, new float[] { float.Parse(commands[12]), float.Parse(commands[13]), float.Parse(commands[14]), float.Parse(commands[15]) });
                                }
                                else
                                {
                                    Global.serverForm.Debug("Invalid arguments in command: " + commands[0]);
                                }
                                break;

                            default:
                                Global.serverForm.Debug("Unknown command");
                                break;
                            }
                        }
                        else
                        {
                            SendDataTCP.SendGlChatMsg("Server", txtChat.Text);
                            txtChat.Text = "";
                        }
                    }
                }
            }
        }
예제 #14
0
        /// <summary>
        ///             Buffer:
        ///                     int PacketNum;
        ///                     int sceneIndex;
        /// </summary>
        public static void SendMatchFound(BaseGameRoom room)
        {
            PacketBuffer buffer = new PacketBuffer();

            buffer.WriteInteger((int)ServerPackets.SMatchFound);
            buffer.WriteInteger((int)room.roomType);
            foreach (ClientTCP player in room.playersTCP)
            {
                foreach (ClientTCP friend in player.friends)
                {
                    SendDataTCP.SendFriendChange(player, friend);
                }
            }
            ServerTCP.SendDataToRoomPlayers(room, buffer.ToArray());
            buffer.Dispose();
        }
예제 #15
0
        public void Add(BaseGameRoom room, int spellIndex, int parentIndex, float[] spawnPos, float[] targetPos, float[] rot, int hp, string nickname)
        {
            int caster = -1;

            for (int i = 0; i < room.PlayersCount; i++)
            {
                if (room.playersTCP[i].nickname.Equals(nickname))
                {
                    caster = i;
                    break;
                }
            }
            int index = Add(room, hp, spawnPos, rot, caster);

            SendDataTCP.SendInstantiate(room, spellIndex, index, parentIndex, spawnPos, targetPos, rot, hp, nickname);
        }
예제 #16
0
 public void AddFriend(string GuideKey)
 {
     foreach (ClientTCP player in Global.clientList)
     {
         if (player.accountData.GuideKey.Equals(GuideKey))
         {
             List <string> Friends = accountData.Friends.ToList();
             if (!Friends.Contains(GuideKey))
             {
                 Friends.Add(GuideKey);
                 accountData.Friends = Friends.AsEnumerable();
                 Global.data.SaveAccount(accountData);
                 SendDataTCP.SendFriendInfo(this, player);
                 break;
             }
             break;
         }
     }
 }
예제 #17
0
        /// <summary>
        ///             Buffer:
        ///                     int PacketNum;
        ///                     string username;
        ///                     string password;
        /// </summary>
        private static void HandleLoginTry(ClientTCP client, byte[] data)
        {
            PacketBuffer buffer = new PacketBuffer();

            buffer.WriteBytes(data);
            buffer.ReadInteger();
            string username = buffer.ReadString();

            if (!Global.data.LoginExist(username))
            {
                SendDataTCP.SendClientAlert(client, "Username does not exist.");
                return;
            }
            if (!Global.data.PasswordIsOkay(username, buffer.ReadString()))
            {
                SendDataTCP.SendClientAlert(client, "Invalid password.");
                return;
            }
            client.LogIn(username);
            buffer.Dispose();
        }
예제 #18
0
 public void LogIn(string username)
 {
     accountData = Global.data.GetAccount(username);
     nickname    = accountData.Nickname;
     playerState = NetPlayerState.InMainLobby;
     clientState = ClientTCPState.MainLobby;
     foreach (string guideKey in accountData.Friends.ToArray())
     {
         foreach (ClientTCP friend in Global.clientList)
         {
             if (friend.accountData.GuideKey.Equals(guideKey))
             {
                 friends.Add(friend);
                 friend.friends.Add(this);
                 SendDataTCP.SendFriendInfo(friend, this);
                 break;
             }
         }
     }
     SendDataTCP.SendLoginOk(nickname, this);
 }
예제 #19
0
 public void LoadComplite(ClientTCP client)
 {
     lock (expectant)
     {
         _loadedTCP[client.ID] = true;
         foreach (bool loaded in _loadedTCP)
         {
             if (!loaded)
             {
                 return;
             }
         }
         foreach (bool loaded in _loadedUDP)
         {
             if (!loaded)
             {
                 return;
             }
         }
         Status = RoomState.Playing;
         SendDataTCP.SendRoomStart(this);
         StartUpdate();
     }
 }
예제 #20
0
        /// <summary>
        ///             Buffer:
        ///                     int PacketNum;
        ///                     string username;
        ///                     string password;
        ///                     string nickname;
        /// </summary>
        private static void HandleRegisterTry(ClientTCP client, byte[] data)
        {
            PacketBuffer buffer = new PacketBuffer();

            buffer.WriteBytes(data);
            buffer.ReadInteger();
            string username = buffer.ReadString();
            string password = buffer.ReadString();
            string nickname = buffer.ReadString();

            if (Global.data.LoginExist(username))
            {
                SendDataTCP.SendClientAlert(client, "Username already exist");
                return;
            }
            if (Global.data.NicknameExist(nickname))
            {
                SendDataTCP.SendClientAlert(client, "Nickname already exist");
                return;
            }
            Global.data.AddAccount(username, password, nickname);
            buffer.Dispose();
            SendDataTCP.SendRegisterOk(client);
        }
예제 #21
0
 public void Close()
 {
     if (clientState != ClientTCPState.Sleep)
     {
         if (clientState == ClientTCPState.Entrance)
         {
             clientState = ClientTCPState.Sleep;
             try
             {
                 socket.Dispose();
             }
             catch (Exception ex)
             {
                 Global.serverForm.Debug(ex + "");
             }
             foreach (ClientTCP friend in friends)
             {
                 SendDataTCP.SendFriendLeave(this, friend);
                 friend.friends.Remove(this);
             }
             Global.clientList.Remove(this);
         }
         else if (clientState == ClientTCPState.MainLobby)
         {
             clientState = ClientTCPState.Sleep;
             try
             {
                 socket.Dispose();
             }
             catch (Exception ex)
             {
                 Global.serverForm.Debug(ex + "");
             }
             foreach (ClientTCP friend in friends)
             {
                 SendDataTCP.SendFriendLeave(this, friend);
                 friend.friends.Remove(this);
             }
             Global.clientList.Remove(this);
             SendDataTCP.SendGlChatMsg("Server", $"Player { nickname } disconnected.");
         }
         else if (clientState == ClientTCPState.GameRoom)
         {
             clientState = ClientTCPState.Sleep;
             if (playerState == NetPlayerState.SearchingForMatch)
             {
                 room.DeletePlayer(this);
             }
             else if (playerState == NetPlayerState.Playing)
             {
                 room.AbortGameSession(this);
             }
             else if (playerState == NetPlayerState.EndPlaying)
             {
                 room.DeletePlayer(this);
             }
             foreach (ClientTCP friend in friends)
             {
                 SendDataTCP.SendFriendLeave(this, friend);
                 friend.friends.Remove(this);
             }
             Global.serverForm.Debug($"GamePlayer {nickname} lost connection");
             Global.clientList.Remove(this);
         }
         Global.serverForm.RemoveClient(this);
     }
 }
예제 #22
0
 public void SetPlayers(ClientTCP client)
 {
     SendDataTCP.SendPlayersSpawned(client, this);
 }
예제 #23
0
 private static void HandleRoomLeave(ClientTCP client, byte[] data)
 {
     SendDataTCP.SendRoomLogOut(client);
     client.room.DeletePlayer(client);
 }
예제 #24
0
 public void SetLoadProgress(ClientTCP client, float loadProgress)
 {
     SendDataTCP.SendEnemyProgress(this, client, client.load = loadProgress);
 }
예제 #25
0
 public void SetGameArea(ClientTCP client)
 {
     SendDataTCP.SendMapData(_mapIndex, client);
 }
예제 #26
0
 /// <summary>
 ///             Buffer:
 ///                     int PacketNum;
 /// </summary>
 private static void HandlePlayerConnect(ClientTCP client, byte[] data)
 {
     SendDataTCP.SendPlayerConnectionOK(client);
     SendDataTCP.SendFriendsInfo(client);
 }
예제 #27
0
 public override void TakeDamage(ClientTCP client, int index, int PhysicDamage, int IgnisDamage, int TerraDamage, int AquaDamage, int CaeliDamage, int PureDamage, bool Heal)
 {
     SendDataTCP.SendDamage(client, index, type, index, PhysicDamage, IgnisDamage, TerraDamage, CaeliDamage, AquaDamage, PureDamage, Heal);
 }
예제 #28
0
 public override void Destroy(BaseGameRoom room)
 {
     SendDataTCP.SendDestroy(room, index, type);
     room.dynamicObjectsList.Destroy(index);
 }