예제 #1
0
        void ProcessChooseNamePacket(ChooseNamePacket pkt)
        {
            bool namechosen = false;
            var cmdx = db0.CreateQuery();
            cmdx.CommandText = "SELECT namechosen FROM accounts WHERE id=@accId";
            cmdx.Parameters.AddWithValue("@accId",account.AccountId);
            object execx = cmdx.ExecuteScalar();
            namechosen = bool.Parse(execx.ToString());

            if (string.IsNullOrEmpty(pkt.Name) ||
                pkt.Name.Length > 10)
            {
                SendPacket(new NameResultPacket()
                {
                    Success = false,
                    Message = "Invalid name"
                });
                return;
            }
            else
            {
                var cmd = db0.CreateQuery();
                cmd.CommandText = "SELECT COUNT(name) FROM accounts WHERE name=@name;";
                cmd.Parameters.AddWithValue("@name", pkt.Name);
                object x = cmd.ExecuteScalar();
                if (int.Parse(x.ToString()) > 0)
                    SendPacket(new NameResultPacket()
                    {
                        Success = false,
                        Message = "Duplicated name"
                    });
                else
                {
                    db0.ReadStats(account);
                    if (account.Credits < 1000 && namechosen == true)
                        SendPacket(new NameResultPacket()
                        {
                            Success = false,
                            Message = "Not enough credits"
                        });
                    else
                    {
                        if (account.NameChosen == false)
                        {
                            cmd = db0.CreateQuery();
                            cmd.CommandText = "UPDATE accounts SET name=@name, namechosen=TRUE WHERE id=@accId;";
                            cmd.Parameters.AddWithValue("@accId", account.AccountId);
                            cmd.Parameters.AddWithValue("@name", pkt.Name);
                            if (cmd.ExecuteNonQuery() > 0)
                            {
                                entity.Name = pkt.Name;
                                entity.NameChosen = true;
                                entity.UpdateCount++;
                                SendPacket(new NameResultPacket()
                                {
                                    Success = true,
                                    Message = "Success!"
                                });
                            }
                            else
                                SendPacket(new NameResultPacket()
                                {
                                    Success = false,
                                    Message = "Internal Error"
                                });
                        }
                        else
                        {
                            cmd = db0.CreateQuery();
                            cmd.CommandText = "UPDATE accounts SET name=@name, namechosen=TRUE WHERE id=@accId;";
                            cmd.Parameters.AddWithValue("@accId", account.AccountId);
                            cmd.Parameters.AddWithValue("@name", pkt.Name);
                            if (cmd.ExecuteNonQuery() > 0)
                            {
                                entity.Credits = db0.UpdateCredit(account, -1000);
                                entity.Name = pkt.Name;
                                entity.NameChosen = true;
                                entity.UpdateCount++;
                                SendPacket(new NameResultPacket()
                                {
                                    Success = true,
                                    Message = "Success!"
                                });
                            }
                            else
                                SendPacket(new NameResultPacket()
                                {
                                    Success = false,
                                    Message = "Internal Error"
                                });
                        }
                    }
                }
            }
        }
예제 #2
0
        void ProcessChooseNamePacket(ChooseNamePacket pkt)
        {
            if (string.IsNullOrEmpty(pkt.Name) ||
                pkt.Name.Length > 10)
            {
                SendPacket(new NameResultPacket()
                {
                    Success = false,
                    Message = "Invalid name"
                });
            }

            var cmd = db.CreateQuery();
            cmd.CommandText = "SELECT COUNT(name) FROM accounts WHERE name=@name;";
            cmd.Parameters.AddWithValue("@name", pkt.Name);
            if ((int)(long)cmd.ExecuteScalar() > 0)
                SendPacket(new NameResultPacket()
                {
                    Success = false,
                    Message = "Duplicated name"
                });
            else
            {
                db.ReadStats(account);
                if (account.NameChosen && account.Credits < 1000)
                    SendPacket(new NameResultPacket()
                    {
                        Success = false,
                        Message = "Not enough credits"
                    });
                else
                {
                    cmd = db.CreateQuery();
                    cmd.CommandText = "UPDATE accounts SET name=@name, namechosen=TRUE WHERE id=@accId;";
                    cmd.Parameters.AddWithValue("@accId", account.AccountId);
                    cmd.Parameters.AddWithValue("@name", pkt.Name);
                    if (cmd.ExecuteNonQuery() > 0)
                    {
                        entity.Credits = db.UpdateCredit(account, -1000);
                        entity.Name = pkt.Name;
                        entity.NameChosen = true;
                        entity.UpdateCount++;
                        SendPacket(new NameResultPacket()
                        {
                            Success = true,
                            Message = ""
                        });
                    }
                    else
                        SendPacket(new NameResultPacket()
                        {
                            Success = false,
                            Message = "Internal Error"
                        });
                }
            }
        }