コード例 #1
0
ファイル: GameClient.cs プロジェクト: JCW801/MyCardGameServer
        public void EnterDungeon(String dungeonName, CardPlayerTransferModel cardPlayer, PlayerCallbackPlayerDelegate _callback)
        {
            var playerModel = new PlayerTransferModel();

            if (socketState == null)
            {
                playerModel.TransferState   = PlayerTransferModel.TransferStateType.Error;
                playerModel.TransferMessage = "没有连接到服务器";
                _callback(playerModel);
                return;
            }
            if (Player == null)
            {
                playerModel.TransferState   = PlayerTransferModel.TransferStateType.Error;
                playerModel.TransferMessage = "没有登录";
                _callback(playerModel);
                return;
            }
            playerModel.TransferRequest = PlayerTransferModel.TransferRequestType.EnterDungeon;
            playerModel.TransferMessage = dungeonName;
            playerModel.CardPlayer      = cardPlayer;

            socketState.CallBackFunction = EnterDungeonCallback;
            NetworkController.Send(socketState, JsonConvert.SerializeObject(playerModel));
            NetworkController.getData(socketState);
            playerCallback = _callback;
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: JCW801/MyCardGameServer
        private static void EnterDungeon(PlayerTransferModel player)
        {
            var t = GameClient.Client.Player.GetRoomMap();
            int i = 0;

            foreach (var item in t[0])
            {
                i = item.Key;
                break;
            }
            GameClient.Client.EnterDungeonRoom(i, EnterDungeonRoom);
        }
コード例 #3
0
ファイル: Server.cs プロジェクト: JCW801/MyCardGameServer
        private void WaitForClientData(SocketState ss)
        {
            string s = ss.SB.ToString();

            ss.SB.Clear();
            try
            {
                PlayerTransferModel player = JsonConvert.DeserializeObject <PlayerTransferModel>(s);
                if (player == null)
                {
                    throw new Exception();
                }

                switch (player.TransferRequest)
                {
                case PlayerTransferModel.TransferRequestType.Login:
                    ClientLogin(player, ss);
                    break;

                case PlayerTransferModel.TransferRequestType.EnterDungeon:
                    ClientEnterDungeon(player, ss);
                    break;

                case PlayerTransferModel.TransferRequestType.EnterDungeonRoom:
                    ClientEnterDungeonRoom(player, ss);
                    break;

                default:
                    throw new Exception();
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("A client has sent illegal data");
                PlayerTransferModel player = new PlayerTransferModel();
                player.TransferState   = PlayerTransferModel.TransferStateType.Error;
                player.TransferMessage = "Illegal data";
                NetworkController.Send(ss, JsonConvert.SerializeObject(player));
            }
            finally
            {
                NetworkController.getData(ss);
            }
        }
コード例 #4
0
ファイル: GameClient.cs プロジェクト: JCW801/MyCardGameServer
        public void Login(String accountName, String password, PlayerCallbackPlayerDelegate _callback)
        {
            var playerModel = new PlayerTransferModel();

            if (socketState == null)
            {
                playerModel.TransferState   = PlayerTransferModel.TransferStateType.Error;
                playerModel.TransferMessage = "没有连接到服务器";
                _callback(playerModel);
                return;
            }
            playerModel.AccountName     = accountName;
            playerModel.Password        = password;
            playerModel.TransferRequest = PlayerTransferModel.TransferRequestType.Login;

            socketState.CallBackFunction = LoginCallback;
            NetworkController.Send(socketState, JsonConvert.SerializeObject(playerModel));
            NetworkController.getData(socketState);
            playerCallback = _callback;
        }
コード例 #5
0
ファイル: Program.cs プロジェクト: JCW801/MyCardGameServer
        private static void Login(PlayerTransferModel player)
        {
            if (player.TransferState != PlayerTransferModel.TransferStateType.Accept)
            {
                Console.WriteLine(player.TransferMessage);
            }
            else
            {
                Console.WriteLine(player.PlayerName + " " + player.PlayerHeroList[0]);
            }

            CardPlayerTransferModel cardPlayer = new CardPlayerTransferModel();

            cardPlayer.MainHero = "Warrior";
            cardPlayer.CardDic  = GameClient.Client.GameDic.HeroDic["Warrior"].HeroBasicCard;

            GameClient.Client.EnterDungeon("TestDungeon", cardPlayer, EnterDungeon);

            //GameClient.Client.Login("TestPlayer2", "password2", Login);
        }
コード例 #6
0
ファイル: GameClient.cs プロジェクト: JCW801/MyCardGameServer
        public void EnterDungeonRoom(int index, PlayerCallbackPlayerDelegate _callback)
        {
            var playerModel = new PlayerTransferModel();

            if (socketState == null)
            {
                playerModel.TransferState   = PlayerTransferModel.TransferStateType.Error;
                playerModel.TransferMessage = "没有连接到服务器";
                _callback(playerModel);
                return;
            }
            if (Player == null)
            {
                playerModel.TransferState   = PlayerTransferModel.TransferStateType.Error;
                playerModel.TransferMessage = "没有登录";
                _callback(playerModel);
                return;
            }
            if (!Player.EnteredDungeon())
            {
                playerModel.TransferState   = PlayerTransferModel.TransferStateType.Error;
                playerModel.TransferMessage = "没有进入副本";
                _callback(playerModel);
                return;
            }
            if (!Player.EnterDungeonRoom(index))
            {
                playerModel.TransferState   = PlayerTransferModel.TransferStateType.Error;
                playerModel.TransferMessage = "无效房间编号";
                _callback(playerModel);
                return;
            }

            playerModel.TransferRequest = PlayerTransferModel.TransferRequestType.EnterDungeonRoom;
            playerModel.TransferMessage = index + "";

            socketState.CallBackFunction = EnterDungeonRoomCallback;
            NetworkController.Send(socketState, JsonConvert.SerializeObject(playerModel));
            NetworkController.getData(socketState);
            playerCallback = _callback;
        }
コード例 #7
0
ファイル: GameClient.cs プロジェクト: JCW801/MyCardGameServer
        private void LoginCallback(SocketState ss)
        {
            socketState = ss;
            PlayerTransferModel playerModel = null;

            try
            {
                playerModel = JsonConvert.DeserializeObject <PlayerTransferModel>(ss.SB.ToString());
            }
            catch
            {
                NetworkController.getData(ss);
                return;
            }

            if (playerModel.TransferState == PlayerTransferModel.TransferStateType.Accept)
            {
                Player = new Player(playerModel);
            }
            playerCallback(playerModel);
            ss.SB = new System.Text.StringBuilder();
        }
コード例 #8
0
ファイル: GameClient.cs プロジェクト: JCW801/MyCardGameServer
        private void EnterDungeonRoomCallback(SocketState ss)
        {
            socketState = ss;
            PlayerTransferModel playerModel = null;

            try
            {
                playerModel = JsonConvert.DeserializeObject <PlayerTransferModel>(ss.SB.ToString());
            }
            catch
            {
                NetworkController.getData(ss);
                return;
            }

            if (playerModel.TransferState == PlayerTransferModel.TransferStateType.Accept)
            {
                int i = Convert.ToInt32(playerModel.TransferMessage);
                Player.SetDungeonRoom(i);
            }

            playerCallback(playerModel);
            ss.SB = new System.Text.StringBuilder();
        }
コード例 #9
0
ファイル: Server.cs プロジェクト: JCW801/MyCardGameServer
        private void ClientEnterDungeonRoom(PlayerTransferModel player, SocketState ss)
        {
            Console.WriteLine(String.Format("{0} wants to enter room.", playerDic[ss].PlayerName, player.TransferMessage));
            if (playerDic.ContainsKey(ss) && player.TransferMessage != null)
            {
                int i = Convert.ToInt32(player.TransferMessage);
                if (playerDic[ss].EnteredDungeon() && playerDic[ss].EnterDungeonRoom(i))
                {
                    player.TransferMessage = playerDic[ss].SetDungeonRoom() + "";
                }
                else
                {
                    throw new Exception();
                }

                player.TransferState = PlayerTransferModel.TransferStateType.Accept;
                NetworkController.Send(ss, JsonConvert.SerializeObject(player));
                Console.WriteLine(String.Format("{0} enters room successfully.", playerDic[ss].PlayerName, player.TransferMessage));
            }
            else
            {
                throw new Exception();
            }
        }
コード例 #10
0
ファイル: Server.cs プロジェクト: JCW801/MyCardGameServer
        private void ClientLogin(PlayerTransferModel player, SocketState ss)
        {
            if (player.AccountName != null && player.Password != null)
            {
                player.AccountName = player.AccountName.ToLower();
                Console.WriteLine("New client wants to login as " + player.AccountName + ".");

                String query = String.Format("SELECT * FROM PlayerAccountData WHERE AccountName = '{0}' AND Password = '******'", player.AccountName, player.Password);
                using (SqlConnection connection = new SqlConnection(sqlConnectionString))
                {
                    using (SqlCommand command = connection.CreateCommand())
                    {
                        command.CommandText = query;
                        connection.Open();

                        using (SqlDataReader reader = command.ExecuteReader())
                        {
                            if (reader.HasRows)
                            {
                                while (reader.Read())
                                {
                                    player.PlayerName = reader["PlayerName"].ToString();
                                    Console.WriteLine(String.Format("New Client successfully login as {0}({1}).", player.AccountName, player.PlayerName));
                                    player.Password      = null;
                                    player.TransferState = PlayerTransferModel.TransferStateType.Accept;
                                }
                            }
                            else
                            {
                                Console.WriteLine("A client wants to login with wrong AccountName/Password pair");
                                player = new PlayerTransferModel();
                                player.TransferState   = PlayerTransferModel.TransferStateType.Decline;
                                player.TransferMessage = "Wrong AccountName/Password pair";
                                NetworkController.Send(ss, JsonConvert.SerializeObject(player));
                                return;
                            }
                        }
                    }

                    player.PlayerHeroList = new List <string>();

                    query = String.Format("SELECT * FROM PlayerHeroData WHERE PlayerName = '{0}'", player.PlayerName);
                    using (SqlCommand command = connection.CreateCommand())
                    {
                        command.CommandText = query;

                        using (SqlDataReader reader = command.ExecuteReader())
                        {
                            if (reader.HasRows)
                            {
                                while (reader.Read())
                                {
                                    player.PlayerHeroList.Add(reader["HeroName"].ToString());
                                }
                            }
                        }
                    }

                    player.PlayerCardList = new Dictionary <string, int>();

                    query = String.Format("SELECT * FROM PlayerCardData WHERE PlayerName = '{0}'", player.PlayerName);
                    using (SqlCommand command = connection.CreateCommand())
                    {
                        command.CommandText = query;

                        using (SqlDataReader reader = command.ExecuteReader())
                        {
                            if (reader.HasRows)
                            {
                                while (reader.Read())
                                {
                                    player.PlayerCardList.Add(reader["CardName"].ToString(), Convert.ToInt32(reader["CardCount"].ToString()));
                                }
                            }
                        }
                    }

                    connection.Close();
                }

                Console.WriteLine(String.Format("User data has sent to {0}({1}), waiting for client action.", player.AccountName, player.PlayerName));
                NetworkController.Send(ss, JsonConvert.SerializeObject(player));
                Player p = new Player(player);
                lock (playerDic)
                {
                    playerDic.Add(ss, p);
                }
            }
            else
            {
                throw new Exception();
            }
        }
コード例 #11
0
ファイル: Server.cs プロジェクト: JCW801/MyCardGameServer
        private void ClientEnterDungeon(PlayerTransferModel player, SocketState ss)
        {
            Console.WriteLine(String.Format("{0} wants to enter {1}.", playerDic[ss].PlayerName, player.TransferMessage));
            if (playerDic.ContainsKey(ss) && player.TransferMessage != null && player.CardPlayer != null && GameDic.DungeonDic.ContainsKey(player.TransferMessage))
            {
                int    count    = 0;
                string heroName = "";
                foreach (var item in player.CardPlayer.CardDic)
                {
                    count += item.Value;
                    if (!GameDic.CardDic.ContainsKey(item.Key))
                    {
                        throw new Exception();
                    }

                    if (heroName == "")
                    {
                        heroName = GameDic.CardDic[item.Key].Owner;
                    }
                    else if (heroName != GameDic.CardDic[item.Key].Owner)
                    {
                        throw new Exception();
                    }

                    if (GameDic.CardDic[item.Key].CardRarity == Card.Rarity.Basic)
                    {
                        if (!GameDic.HeroDic[heroName].HeroBasicCard.ContainsKey(item.Key) || GameDic.HeroDic[heroName].HeroBasicCard[item.Key] < item.Value)
                        {
                            throw new Exception();
                        }
                    }
                    else
                    {
                        if (!playerDic[ss].HasCard(item.Key, item.Value))
                        {
                            throw new Exception();
                        }
                    }
                }
                if (count != GameDic.DungeonDic[player.TransferMessage].DungeonAllowedCardCount)
                {
                    throw new Exception();
                }
                if (!playerDic[ss].HasHero(heroName) || heroName != player.CardPlayer.MainHero)
                {
                    throw new Exception();
                }
                if (player.CardPlayer.SubHero != null && !playerDic[ss].HasHero(player.CardPlayer.SubHero))
                {
                    throw new Exception();
                }
                var temp = GameDic.DungeonDic[player.TransferMessage].Generate();
                if (!playerDic[ss].EnterDungeon(temp, player.CardPlayer))
                {
                    throw new Exception();
                }

                player.TransferState = PlayerTransferModel.TransferStateType.Accept;
                player.Dungeon       = temp;
                NetworkController.Send(ss, JsonConvert.SerializeObject(player));
                Console.WriteLine(String.Format("{0} enters {1} successfully.", playerDic[ss].PlayerName, player.TransferMessage));
            }
            else
            {
                throw new Exception();
            }
        }
コード例 #12
0
ファイル: Program.cs プロジェクト: JCW801/MyCardGameServer
 private static void EnterDungeonRoom(PlayerTransferModel player)
 {
     Player p = GameClient.Client.Player;
 }