コード例 #1
0
ファイル: Program.cs プロジェクト: wagnercamara/Curumim
        private static void InsertBuyItem(List <dynamic> DinBuy, ThreadClient client, Int32 idPlayer, Int32 listSize, int emerald)
        {
            if (DinBuy.Count == listSize)
            {
                bool     InsertSucess           = false;
                Int32    id_tbItem              = 0;
                Int32    amountItemPurchase     = 0;
                Int32    valueUnitItemPurchase  = 0;
                Int32    valueTotalItemPurchase = 0;
                DateTime dateTime  = DateTime.Now;
                SQLQuery sQLQuery  = new SQLQuery();
                Int32?   idPuchese = sQLQuery.SqlSetPurchase(dateTime, idPlayer);

                if (idPuchese != null)
                {
                    foreach (dynamic dynBuy in BuyList)
                    {
                        id_tbItem              = dynBuy.id_tbItem;
                        amountItemPurchase     = dynBuy.amountItemPurchase;
                        valueUnitItemPurchase  = dynBuy.valueUnitItemPurchase;
                        valueTotalItemPurchase = dynBuy.valueTotalItemPurchase;

                        InsertSucess = sQLQuery.SqlSetItemPuchase((Int32)idPuchese, id_tbItem, amountItemPurchase, valueUnitItemPurchase, valueTotalItemPurchase);
                        if (InsertSucess == false)
                        {
                            break;
                        }
                    }
                    switch (InsertSucess)
                    {
                    case true:
                        UpdateArsenal(client, idPlayer, DinBuy, emerald);
                        break;

                    case false:
                        BuyPlayers.Remove(idPlayer);
                        client.SendMessage(new { Type = STORE_TYPE_SET_BUY_ERRO });
                        break;
                    }
                }
                else
                {
                    BuyPlayers.Remove(idPlayer);
                    client.SendMessage(new { Type = STORE_TYPE_SET_BUY_ERRO });
                }
            }
            else
            {
                client.SendMessage(new { Type = PROGRESSBAR_TYPE_NEXT });
            }
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: wagnercamara/Curumim
        private static void SetOffOrOnPlayer(ThreadClient client, int idPlayer, int OffOn)
        {
            SQLQuery sQLQuery = new SQLQuery();
            Boolean  OK       = sQLQuery.SqlSetOffOnLine(idPlayer, OffOn);

            switch (OK)
            {
            case true:
                Console.WriteLine("Status Gravado");
                switch (OffOn)
                {
                case 1:
                    Console.WriteLine("Client ONLINE");
                    if (MessegeOnLine.ContainsKey(idPlayer) == false)
                    {
                        MessegeOnLine.Add(idPlayer, client);
                        client.SendMessage(new
                        {
                            Type = MESSAGE_TYPE_SET_PLAYER_ON_LINE_SUCCESS
                        });
                    }
                    else
                    {
                        MessegeOnLine.Remove(idPlayer);

                        MessegeOnLine.Add(idPlayer, client);
                        client.SendMessage(new
                        {
                            Type = MESSAGE_TYPE_SET_PLAYER_ON_LINE_SUCCESS
                        });
                    }
                    break;

                case 0:
                    Console.WriteLine("Client OFFLINE");
                    if (MessegeOnLine.ContainsKey(idPlayer) == true)
                    {
                        MessegeOnLine.Remove(idPlayer);
                    }
                    break;
                }
                break;

            case false:
                Console.WriteLine("status não gravado.");
                client.SendMessage(new { Type = MESSAGE_TYPE_SET_PLAYER_ON_LINE_ERRO });
                break;
            }
            UpdateStatus(idPlayer);
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: wagnercamara/Curumim
        private static void GetSearchPlayer(ThreadClient client, string login, bool v)
        {
            SQLQuery sQLQuery = new SQLQuery();
            dynamic  dynamic  = sQLQuery.GetSearchPlayer(login, v);

            client.SendMessage(dynamic);
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: wagnercamara/Curumim
        private static void GetPlayerPosition(ThreadClient client, int idPlayer)
        {
            SQLQuery sQLQuery = new SQLQuery();
            dynamic  dynamic  = sQLQuery.GetPlayerPosition(idPlayer);

            client.SendMessage(dynamic);
        }
コード例 #5
0
ファイル: Program.cs プロジェクト: wagnercamara/Curumim
        private static void GetProfilePlayer(ThreadClient client, string login, string password)
        {
            SQLQuery sQLQuery = new SQLQuery();
            dynamic  dynamic  = sQLQuery.LoginGetPlayer(login, password);

            client.SendMessage(dynamic);
        }
コード例 #6
0
ファイル: Program.cs プロジェクト: wagnercamara/Curumim
        private static void SetRoomPlayer(ThreadClient client, string loginPlayer, int typeRoom, int betRoom, bool waiting)
        {
            switch (waiting)
            {
            case true:
                if (Rooms[typeRoom] == null)
                {
                    Rooms[typeRoom] = new Dictionary <string, ThreadClient>();
                }
                Console.WriteLine($"Client Enter Room {typeRoom}");
                if (Rooms[typeRoom].ContainsKey(loginPlayer) == false)
                {
                    Rooms[typeRoom].Add(loginPlayer, client);
                    if (Rooms[typeRoom].Count() < 2)
                    {
                        client.SendMessage(new { Type = BATTLE_TYPE_ENTERED_BATTLE_SUCCESS });
                    }
                    if (Rooms[typeRoom].Count() == 2)
                    {
                        CreateBattle(typeRoom, betRoom);
                    }
                }
                break;

            case false:
                Console.WriteLine($"Client Exit Room { typeRoom}");
                if (Rooms[typeRoom].ContainsKey(loginPlayer) == true)
                {
                    Rooms[typeRoom].Remove(loginPlayer);
                }
                break;
            }
        }
コード例 #7
0
ファイル: Program.cs プロジェクト: wagnercamara/Curumim
        private static void NewMessageChatGlobal(ThreadClient client, int sender_id_tbPlayer, string messageMessage, DateTime dateTimeMessage, string loginSender)
        {
            SQLQuery sQLQuery = new SQLQuery();
            Boolean  OkSend   = sQLQuery.SqlInsertMenssageGlobal(sender_id_tbPlayer, messageMessage, dateTimeMessage);

            switch (OkSend)
            {
            case true:
                foreach (ThreadClient threadClient in Login_threadClients)
                {
                    string sender  = loginSender;
                    string message = messageMessage;
                    string date    = dateTimeMessage.ToString();
                    threadClient.SendMessage(new { Type = GET_INFO_GAME_SUCESS, Function = "message", sender, message, date });
                }
                break;

            case false:
                client.SendMessage(new
                {
                    Type = GET_INFO_GAME_ERRO
                });
                break;
            }
        }
コード例 #8
0
ファイル: Program.cs プロジェクト: wagnercamara/Curumim
 private static void SyncLocalIndian(int newLocal, int oldLocal, string loginPlayer)
 {
     if (BattlePlayers.ContainsKey(loginPlayer))
     {
         ThreadClient thread = BattlePlayers[loginPlayer];
         thread.SendMessage(new { Type = BATTLE_TYPE_SYNC_LOCAL_INDIAN_SUCCESS, oldLocal, newLocal });
     }
 }
コード例 #9
0
ファイル: Program.cs プロジェクト: wagnercamara/Curumim
        private static void SetNewMessage(ThreadClient client, int sender_id_tbPlayer, int receiver_id_tbPlayer, string messageMessage, DateTime dateTimeMessage, string loginSender)
        {
            SQLQuery sQLQuery = new SQLQuery();
            Boolean  OkSend   = sQLQuery.SqlInsertMenssage(sender_id_tbPlayer, receiver_id_tbPlayer, messageMessage, dateTimeMessage);
            Boolean  OK       = MessegeOnLine.ContainsKey(receiver_id_tbPlayer);

            switch (OkSend)
            {
            case true:
                switch (OK)
                {
                case true:
                    ThreadClient receiver = MessegeOnLine[receiver_id_tbPlayer];
                    string       format   = "yyyy/MM/dd HH:mm:ss";
                    string       date     = dateTimeMessage.ToString(format);
                    receiver.SendMessage(new
                    {
                        Type = MESSAGE_TYPE_NEW_MESSAGE_ONLINE,
                        loginSender,
                        sender_id_tbPlayer,
                        messageMessage,
                        date
                    });
                    break;

                case false:
                    client.SendMessage(new
                    {
                        Type    = MESSAGE_TYPE_SEVER,
                        message = "Server: Client está Offline, sua mensagem foi gravada",
                    });
                    break;
                }
                break;

            case false:
                client.SendMessage(new
                {
                    Type    = MESSAGE_TYPE_SEVER,
                    message = "Server Log: Erro ao gravar mensagem no banco de dados",
                });
                break;
            }
        }
コード例 #10
0
ファイル: Program.cs プロジェクト: wagnercamara/Curumim
        private static void GetItemArsenal(ThreadClient client, int idPlayer)
        {
            SQLQuery       sQLQuery = new SQLQuery();
            List <dynamic> dynamics = sQLQuery.SqlGetItemArsenal(idPlayer);

            foreach (dynamic din in dynamics)
            {
                client.SendMessage(din);
            }
        }
コード例 #11
0
ファイル: Program.cs プロジェクト: wagnercamara/Curumim
        private static void GetMessageChat(ThreadClient client, int sender, int receiver)
        {
            SQLQuery       sQLQuery = new SQLQuery();
            List <dynamic> dynamics = sQLQuery.SqlGetMessage(sender, receiver);

            foreach (dynamic din in dynamics)
            {
                client.SendMessage(din);
            }
        }
コード例 #12
0
ファイル: Program.cs プロジェクト: wagnercamara/Curumim
        private static void GetRankig(ThreadClient client)
        {
            SQLQuery       sQLQuery = new SQLQuery();
            List <dynamic> dynamics = sQLQuery.SqlGetRanking();

            foreach (dynamic din in dynamics)
            {
                client.SendMessage(din);
            }
        }
コード例 #13
0
ファイル: Program.cs プロジェクト: wagnercamara/Curumim
        private static void DestroyedButton(int[] locals, string loginPlayerEnemy, int typeItem)
        {
            ThreadClient clientee = BattlePlayers[loginPlayerEnemy];

            clientee.SendMessage(new
            {
                Type = BATTLE_TYPE_SET_DESTROYED_SIDE_SUCECSS,
                locals,
                typeItem
            });
        }
コード例 #14
0
ファイル: Program.cs プロジェクト: wagnercamara/Curumim
 private static void NewMessagechatBattle(ThreadClient client, string messageMessage, string login, string loginPlayerEnemy)
 {
     if (BattlePlayers.ContainsKey(login))
     {
         ThreadClient thread = BattlePlayers[loginPlayerEnemy];
         thread.SendMessage(new { Type = NEW_MESSAGE_CHAT_BATTLE_SUCESS, messageMessage = $"{login}: {messageMessage}" });
     }
     else
     {
         client.SendMessage(new { Type = NEW_MESSAGE_CHAT_BATTLE_ERRO });
     }
 }
コード例 #15
0
ファイル: Program.cs プロジェクト: wagnercamara/Curumim
        private static void UpdatePlayer(ThreadClient client, string loginPlayer, string passwordPlayer, string secretPhresePlayer)
        {
            SQLQuery sQLQuery = new SQLQuery();
            Boolean  OK       = sQLQuery.SqlUpdatePassword(loginPlayer, passwordPlayer, secretPhresePlayer);

            switch (OK)
            {
            case true:
                client.SendMessage(new
                {
                    Type = FORGOT_PASSWORD_TYPE_RETURN_SUCCESS
                });
                break;

            case false:
                client.SendMessage(new
                {
                    Type = FORGOT_PASSWORD_TYPE_RETURN_ERROR
                });
                break;
            }
        }
コード例 #16
0
ファイル: Program.cs プロジェクト: wagnercamara/Curumim
        private static void SetNewPlayer(ThreadClient client, string fullNamePlayer, string loginPlayer, string passwordPlayer, string secretPhresePlayer, string avatarPlayer)
        {
            SQLQuery sQLQuery = new SQLQuery();
            Boolean  OK       = sQLQuery.SqlSetNewPlayer(fullNamePlayer, loginPlayer, passwordPlayer, secretPhresePlayer, avatarPlayer);

            switch (OK)
            {
            case true:
                client.SendMessage(new
                {
                    Type = REGISTER_TYPE_RETURN_SUCCESS
                });
                break;

            case false:
                client.SendMessage(new
                {
                    Type = REGISTER_TYPE_RETURN_ERROR
                });
                break;
            }
        }
コード例 #17
0
ファイル: Program.cs プロジェクト: wagnercamara/Curumim
        private static void UpdateArsenal(ThreadClient client, int idPlayer, List <dynamic> DinBuy, int emerald)
        {
            Console.WriteLine("ARSENAL_TYPE_GET_ITEM");
            Boolean  InsertSucess       = false;
            Int32    id_tbItem          = 0;
            Int32    amountItemPurchase = 0;
            SQLQuery sQLQuery           = new SQLQuery();

            foreach (dynamic dynBuy in BuyList)
            {
                id_tbItem          = dynBuy.id_tbItem;
                amountItemPurchase = dynBuy.amountItemPurchase;

                InsertSucess = sQLQuery.SqlSetOrUpdateArsenal(idPlayer, id_tbItem, amountItemPurchase);
                if (InsertSucess == false)
                {
                    break;
                }
            }
            if (InsertSucess == true)
            {
                BuyPlayers.Remove(idPlayer);
                if (SetEmeraldUpdatePlayer(client, idPlayer, emerald) == true)
                {
                    GetItemArsenal(client, idPlayer);
                    client.SendMessage(new { Type = STORE_TYPE_SET_BUY_SUCCESS });
                }
                else
                {
                    client.SendMessage(new { Type = ARSENAL_TYPE_GET_ITEM_ERRO });
                }
            }
            else
            {
                client.SendMessage(new { Type = ARSENAL_TYPE_GET_ITEM_ERRO });
            }
        }
コード例 #18
0
ファイル: Program.cs プロジェクト: gkamchen/Tower_Destroyer2D
        static void OnClientReceiveMessage(object sender, EventArgs eventArgs)
        {
            MessageEventArgs messageEventArgs = eventArgs as MessageEventArgs;

            if (messageEventArgs != null)
            {
                Message message = messageEventArgs.Message;

                int          type   = message.GetInt32("type");
                ThreadClient client = sender as ThreadClient;

                switch (type)
                {
                case MESSAGE_TYPE_GET_MESSAGES:
                    if (client != null)
                    {
                        List <dynamic> messages = GetMessages();

                        foreach (dynamic messageFromDB in messages)
                        {
                            client.SendMessage(messageFromDB);
                        }
                    }
                    break;

                case MESSAGE_TYPE_SEND_NEW_MESSAGE:
                    int    userIdNewMsg = message.GetInt32("userId");
                    string userName     = message.GetString("userName");
                    string namePlayer   = message.GetString("namePlayer");
                    string dateTime     = message.GetString("dateTime");
                    string messageText  = message.GetString("messageText");

                    if (InsertMessage(userIdNewMsg, messageText) == true)
                    {
                        foreach (ThreadClient clientNewMsg in clients)
                        {
                            clientNewMsg.SendMessage(new
                            {
                                type = MESSAGE_TYPE_READ_NEW_MESSAGE,
                                userName,
                                namePlayer,
                                dateTime,
                                messageText
                            });
                        }
                    }
                    break;

                case MESSAGE_TYPE_INSERT_USER_REQUEST:
                    if (client != null)
                    {
                        string name         = message.GetString("name");
                        string username     = message.GetString("username");
                        string password     = message.GetString("password");
                        string birthDate    = message.GetString("birthDate");
                        string securityText = message.GetString("securityText");

                        bool userInserted = InsertUser(name, username, password, birthDate, securityText);

                        if (userInserted == true)
                        {
                            client.SendMessage(new
                            {
                                type    = MESSAGE_TYPE_INSERT_USER_SUCCESS,
                                success = "Usuário cadastrado com sucesso"
                            });
                        }
                        else
                        {
                            if (uniqueUser == false)
                            {
                                client.SendMessage(new
                                {
                                    type  = MESSAGE_TYPE_INSERT_USER_ERROR,
                                    error = $"Já existe um usuário '{username}' cadastrado no sistema"
                                });
                            }
                            else
                            {
                                client.SendMessage(new
                                {
                                    type  = MESSAGE_TYPE_INSERT_USER_ERROR,
                                    error = "Falha ao tentar cadastrar o usuário, favor tentar novamente"
                                });
                            }
                        }
                    }
                    break;

                case MESSAGE_TYPE_GET_USER_REQUEST:
                    if (client != null)
                    {
                        string login    = message.GetString("login");
                        string password = message.GetString("password");

                        dynamic userData     = null;
                        bool    hasException = false;

                        try
                        {
                            userData = GetUser(login, password);
                        }
                        catch
                        {
                            hasException = true;
                        }

                        if (hasException)
                        {
                            client.SendMessage(new
                            {
                                type  = MESSAGE_TYPE_GET_USER_ERROR,
                                error = "Falha ao tentar fazer o login, favor tentar novamente"
                            });
                        }
                        else
                        {
                            if (userData != null)
                            {
                                client.SendMessage(userData);
                            }
                            else
                            {
                                client.SendMessage(new
                                {
                                    type  = MESSAGE_TYPE_GET_USER_ERROR,
                                    error = "Falha ao tentar fazer o login, usuário ou senha inválido"
                                });
                            }
                        }
                    }
                    break;

                case MESSAGE_TYPE_RECOVERY_USER_PASSWORD_REQUEST:
                    if (client != null)
                    {
                        string username     = message.GetString("username");
                        string birthDate    = message.GetString("birthDate");
                        string securityText = message.GetString("securityText");

                        dynamic recoveryData = null;
                        bool    hasException = false;

                        try
                        {
                            recoveryData = GetValidateUser(username, birthDate, securityText);
                        }
                        catch
                        {
                            hasException = true;
                        }


                        if (hasException)
                        {
                            client.SendMessage(new
                            {
                                type  = MESSAGE_TYPE_RECOVERY_USER_PASSWORD_ERROR,
                                error = "Falha ao recuperar dados, favor tentar novamente"
                            });
                        }
                        else
                        {
                            if (recoveryData != null)
                            {
                                client.SendMessage(recoveryData);
                            }
                            else
                            {
                                client.SendMessage(new
                                {
                                    type  = MESSAGE_TYPE_RECOVERY_USER_PASSWORD_ERROR,
                                    error = "Falha ao recuperar dados, favor tentar novamente"
                                });
                            }
                        }
                    }
                    break;

                case MESSAGE_TYPE_UPDATE_PASSWORD_REQUEST:
                    if (client != null)
                    {
                        int    idPlayer = message.GetInt32("idPlayer");
                        string password = message.GetString("password");

                        bool updateResult = false;
                        bool hasException = false;

                        try
                        {
                            updateResult = UpdatePassword(idPlayer, password);
                        }
                        catch
                        {
                            hasException = true;
                        }


                        if (hasException)
                        {
                            client.SendMessage(new
                            {
                                type  = MESSAGE_TYPE_UPDATE_PASSWORD_ERROR,
                                error = "Falha ao recuperar dados, favor tentar novamente"
                            });
                        }
                        else
                        {
                            if (updateResult == true)
                            {
                                client.SendMessage(new
                                {
                                    type = MESSAGE_TYPE_UPDATE_PASSWORD_SUCCESS
                                });
                            }
                            else
                            {
                                client.SendMessage(new
                                {
                                    type  = MESSAGE_TYPE_UPDATE_PASSWORD_ERROR,
                                    error = "Falha ao recuperar dados, favor tentar novamente"
                                });
                            }
                        }
                    }
                    break;

                case MESSAGE_TYPE_MATCH_DATA_REQUEST:
                    totPlayersInMatch++;

                    if (totPlayersInMatch == 2)
                    {
                        totPlayersInMatch = 0;
                        StartMatch();
                    }
                    else
                    {
                        client.SendMessage(new
                        {
                            type = MESSAGE_TYPE_MATCH_DATA_WAITING
                        });
                    }
                    break;

                case MESSAGE_TYPE_MATCH_ENEMY_ATTACK:
                    if (client != null)
                    {
                        foreach (ThreadClient threadClient in clients)
                        {
                            if (threadClient.GetNumber() != client.GetNumber())
                            {
                                threadClient.SendMessage(new
                                {
                                    type   = MESSAGE_TYPE_MATCH_ENEMY_ATTACK,
                                    line   = message.GetInt32("line"),
                                    column = message.GetInt32("column")
                                });
                            }
                        }
                    }
                    break;

                case MESSAGE_TYPE_MATCH_END_GAME:
                    int  isWinner = 0, expPlayer1 = 0, expPlayer2 = 0;
                    char sitPlayer1 = 'N', sitPlayer2 = 'N';

                    if (client != null)
                    {
                        foreach (ThreadClient threadClient in clients)
                        {
                            if (message.GetInt32("myUnities") != 0)
                            {
                                isWinner = 1;
                            }
                            threadClient.SendMessage(new
                            {
                                type         = MESSAGE_TYPE_MATCH_END_GAME,
                                myUnities    = message.GetInt32("myUnities"),
                                enemyUnities = message.GetInt32("enemyUnities"),
                                isWinner     = isWinner
                            });
                        }

                        if (isWinner == 1)
                        {
                            sitPlayer1 = 'S';
                            expPlayer1 = 100;
                            expPlayer2 = 20;
                        }
                        else
                        {
                            sitPlayer2 = 'S';
                            expPlayer1 = 20;
                            expPlayer2 = 100;
                        }
                        EndMatch(1, 2, "0", sitPlayer1, sitPlayer2, expPlayer1, expPlayer2);
                    }
                    break;
                }
            }
        }