Example #1
0
        public void SavePlayerPosition(string charname, string x, string y, string z, int clientId)
        {
            string RetVar = "";

            pBuilder = new ProtocolBuilder("SavePlayerPosition");
            pBuilder.Add(charname);
            pBuilder.Add(x);
            pBuilder.Add(y);
            pBuilder.Add(z, true);

            using (TesteunityEntities contexto = new TesteunityEntities())
            {
                //Verifica se já existe o username no BD
                var queryPlayer = (from p in contexto.Players
                                   where p.Nome == charname
                                   select p).SingleOrDefault();

                Player player = new Player();
                player      = queryPlayer;
                player.PosX = Convert.ToDouble(x);
                player.PosY = Convert.ToDouble(y);
                player.PosZ = Convert.ToDouble(z);

                contexto.SaveChanges();
            }


            Server._sProtocolResponse = RetVar;
        }
Example #2
0
        public void RegisterLogin(string userParam, string PwdParam, string emailParam, string firsLogin, int clientId)
        {
            string RetVar = "";

            pBuilder = new ProtocolBuilder("RegisterLogin");
            pBuilder.Add(userParam);
            pBuilder.Add(PwdParam);
            pBuilder.Add(emailParam);
            pBuilder.Add(firsLogin, true);

            using (TesteunityEntities contexto = new TesteunityEntities())
            {
                //Verifica se já existe o username no BD
                var queryUserName = (from u in contexto.Users
                                     where u.nome == userParam
                                     select u).ToList();

                var queryEmail = (from u in contexto.Users
                                  where u.email == emailParam
                                  select u).ToList();

                if (queryUserName.Count == 0)
                {
                    if (queryEmail.Count == 0)
                    {
                        User user = new User();
                        user.nome  = userParam;
                        user.senha = PwdParam;
                        user.email = emailParam;
                        if (firsLogin == "1")
                        {
                            user.primeirologin = true;
                        }

                        try
                        {
                            contexto.Users.Add(user);
                            contexto.SaveChanges();
                            RetVar = "[Regok]"; //Cadastro realizado com sucesso!
                        }
                        catch (Exception e)
                        {
                            RetVar = "[Regnotsaved]"; //User not saved, try again later!
                        }
                    }
                    else
                    {
                        RetVar = "[Regemailexistent]"; //E-mail já utilizado, tente cadastrar outro
                    }
                }
                else
                {
                    RetVar = "[Regnameexistent]"; //Username já existe, tente cadastrar outro!
                }
            }



            Server._sProtocolResponse = RetVar;
        }
Example #3
0
        public void RequestPlayerDetails(string playerName, string nada, int clientId)
        {
            string RetVar = "";

            pBuilder = new ProtocolBuilder("RequestPlayerDetails");
            pBuilder.Add(playerName);
            pBuilder.Add(nada, true);

            using (TesteunityEntities contexto = new TesteunityEntities())
            {
                //StringBuilder sb = new StringBuilder();

                string details;

                //Verifica se já existe o username no BD
                var queryPlayer = (from p in contexto.Players
                                   where (p.Nome == playerName)
                                   select p).SingleOrDefault();


                details = queryPlayer.Nome + "|" +
                          queryPlayer.Sexo + "|" +
                          queryPlayer.Nivel.ToString() + "|" +
                          queryPlayer.Vida.ToString() + "|" +
                          queryPlayer.Mana.ToString() + "|" +
                          queryPlayer.PosX.ToString() + "|" +
                          queryPlayer.PosY.ToString() + "|" +
                          queryPlayer.PosZ.ToString() + "|" +
                          queryPlayer.valorvermelhopelemasc.ToString() + "|" +
                          queryPlayer.valorverdepelemasc.ToString() + "|" +
                          queryPlayer.valorazulpelemasc.ToString() + "|" +
                          queryPlayer.valorvermelhocabelomasc.ToString() + "|" +
                          queryPlayer.valorverdecabelomasc + "|" +
                          queryPlayer.valorazulcabelomasc + "|" +
                          queryPlayer.valorvermelhoblusamasc + "|" +
                          queryPlayer.valorverdeblusamasc + "|" +
                          queryPlayer.valorazulblusamasc + "|" +
                          queryPlayer.valorvermelhocalcamasc + "|" +
                          queryPlayer.valorverdecalcamasc + "|" +
                          queryPlayer.valorazulcalcamasc;



                RetVar = "[Chardetails]" + details; //detalhes
            }

            Server._sProtocolResponse = RetVar;
        }
        public void RequestListOfPlayers(string userNameParam, string nada, int clientId)
        {
            string RetVar = "";

            pBuilder = new ProtocolBuilder("RequestListOfPlayers");
            pBuilder.Add(userNameParam);
            pBuilder.Add(nada, true);

            using (TesteunityEntities contexto = new TesteunityEntities())
            {
                StringBuilder sb = new StringBuilder();

                //Verifica se já existe o username no BD
                var queryuserName = (from u in contexto.Users
                                     where (u.nome == userNameParam)
                                     select u).SingleOrDefault();


                var queryPlayers = (from p in contexto.Players
                                    where (p.ID_USER_PLAYERS == queryuserName.ID)
                                    select p).ToList();


                foreach (var p in queryPlayers)
                {
                    if (queryPlayers.IndexOf(p) == queryPlayers.Count - 1)
                    {
                        sb.Append(p.Nome);
                    }
                    else
                    {
                        sb.Append(p.Nome);
                        sb.Append("|");
                    }
                }

                if (queryPlayers.Count == 0)
                {
                    RetVar = "[Charsinexistents]"; //no players registered for this account
                }
                else
                {
                    RetVar = "[Charsexistents]" + sb.ToString(); //Players registered!
                }
            }

            Server._sProtocolResponse = RetVar;
        }
Example #5
0
        public void LoginMember(string userParam, string PwdParam, string firstlogin, int clientId)
        {
            string RetVar = "";

            pBuilder = new ProtocolBuilder("LoginMemb");
            pBuilder.Add(userParam);
            pBuilder.Add(PwdParam);
            pBuilder.Add(firstlogin, true);

            using (TesteunityEntities contexto = new TesteunityEntities())
            {
                //Verifica se já existe o username no BD
                var query = (from u in contexto.Users
                             where (u.nome == userParam) && (u.senha == PwdParam)
                             select u).SingleOrDefault();


                if (query != null)
                {
                    if (query.senha != PwdParam)
                    {
                        RetVar = "[Loginfail]"; //Login failed!
                    }
                    else
                    {
                        if (query.primeirologin == true)
                        {
                            RetVar = "[Loginok1]"; //Login ok! Welcome to your first time here.
                            query.primeirologin = false;
                            contexto.SaveChanges();
                        }
                        else
                        {
                            RetVar = "[Loginok]"; //Login ok!
                        }
                    }
                }
                else
                {
                    RetVar = "[Loginfail]"; //Login failed!
                }
            }

            Server._sProtocolResponse = RetVar;
        }
Example #6
0
        public void CreateCharacter(string nameUser, string namePlayer, string genre, string level, string life,
                                    string mana, string posx, string posy, string posz,
                                    string sredvalueskintmale, string sgreenvalueskinmale, string sbluevalueskinmale, string sredvaluehairtmale,
                                    string sgreenvaluehairtmale, string sbluevaluehairtmale, string sredvalueshirtmale, string sgreenvalueshirtmale,
                                    string sbluevalueshirtmale, string sredvaluepantsmale, string sgreenvaluepantsmale, string sbluevaluepantsmale,
                                    int clientId)
        {
            string RetVar = "";

            pBuilder = new ProtocolBuilder("CreateCharacter");
            pBuilder.Add(nameUser);
            pBuilder.Add(namePlayer);
            pBuilder.Add(genre);
            pBuilder.Add(life);
            pBuilder.Add(mana);
            pBuilder.Add(posx);
            pBuilder.Add(posy);
            pBuilder.Add(posz);
            pBuilder.Add(sredvalueskintmale);
            pBuilder.Add(sgreenvalueskinmale);
            pBuilder.Add(sbluevalueskinmale);
            pBuilder.Add(sredvaluehairtmale);
            pBuilder.Add(sgreenvaluehairtmale);
            pBuilder.Add(sbluevaluehairtmale);
            pBuilder.Add(sredvalueshirtmale);
            pBuilder.Add(sgreenvalueshirtmale);
            pBuilder.Add(sbluevalueshirtmale);
            pBuilder.Add(sredvaluepantsmale);
            pBuilder.Add(sgreenvaluepantsmale);
            pBuilder.Add(sbluevaluepantsmale, true);


            using (TesteunityEntities contexto = new TesteunityEntities())
            {
                var queryUserName = (from u in contexto.Users
                                     where u.nome == nameUser
                                     select u).SingleOrDefault();

                var queryNamePlayer = (from p in contexto.Players
                                       where p.Nome == namePlayer
                                       select p).SingleOrDefault();

                if (queryNamePlayer != null)
                {
                    RetVar = "[Charnameexistent]"; //Name already chosen, try another one!
                }
                else
                {
                    if (queryUserName != null)
                    {
                        Player player = new Player();
                        player.ID_USER_PLAYERS         = queryUserName.ID;
                        player.Nome                    = namePlayer;
                        player.Sexo                    = genre;
                        player.Nivel                   = Convert.ToInt32(level);
                        player.Vida                    = Convert.ToDouble(life);
                        player.Mana                    = Convert.ToDouble(mana);
                        player.PosX                    = Convert.ToDouble(posx);
                        player.PosY                    = Convert.ToDouble(posy);
                        player.PosZ                    = Convert.ToDouble(posz);
                        player.valorvermelhopelemasc   = Convert.ToInt32(sredvalueskintmale);
                        player.valorverdepelemasc      = Convert.ToInt32(sgreenvalueskinmale);
                        player.valorazulpelemasc       = Convert.ToInt32(sbluevalueskinmale);
                        player.valorvermelhocabelomasc = Convert.ToInt32(sredvaluehairtmale);
                        player.valorverdecabelomasc    = Convert.ToInt32(sgreenvaluehairtmale);
                        player.valorazulcabelomasc     = Convert.ToInt32(sbluevaluehairtmale);
                        player.valorvermelhoblusamasc  = Convert.ToDouble(sredvalueshirtmale);
                        player.valorverdeblusamasc     = Convert.ToDouble(sgreenvalueshirtmale);
                        player.valorazulblusamasc      = Convert.ToDouble(sbluevalueshirtmale);
                        player.valorvermelhocalcamasc  = Convert.ToDouble(sredvaluepantsmale);
                        player.valorverdecalcamasc     = Convert.ToDouble(sgreenvaluepantsmale);
                        player.valorazulcalcamasc      = Convert.ToDouble(sbluevaluepantsmale);

                        try
                        {
                            contexto.Players.Add(player);
                            contexto.SaveChanges();
                            RetVar = "[Charsaved]"; //Character Saved!
                        }
                        catch (Exception)
                        {
                            RetVar = "[Charnotsaved]";
                        }
                    }
                }
            }

            Server._sProtocolResponse = RetVar;
        }