/* Copyright 2010 © by YeZZx aka Crunkx */
using System;

namespace LoginServer
{

    class CP_PATCHER_PACKET : cClientPacketHandler
    {
        public override void Handle(cClientPacketHandler Packet, cClient Client)
        {
            Client.Send(new SP_PATCHER_PACKET());
        }
    }
    class CP_SET_NICKNAME : cClientPacketHandler
    {
        public override void Handle(cClientPacketHandler Packet, cClient Client)
        {
            try
            {
                string Nickname = Packet.getBlock();

                if (Nickname.Length > 3)
                {
                    cMain.DBClass.conn.ExecuteQuery("UPDATE account SET Login1='0' WHERE userID='" + Client.getUserID() + "'");
                    cMain.DBClass.conn.ExecuteQuery("UPDATE account SET nickname='" + Nickname + "' WHERE userID='" + Client.getUserID() + "'");
                    
                    Client.setNickname(Nickname);
                    Client.Send(new SP_SERVER_LIST(Client));
                    new cLog(C.MSG_INFO, "User ID: " + Client.getUserID() + "setted he nickname to: " + Client.getNickname());
                }
                else
                {
                    Client.Send(new SP_SERVER_LIST(SP_SERVER_LIST.errorCodes.Nickname));
                }
            }
            catch{}
        }
    }
    class CP_LOGIN_PACKET : cClientPacketHandler
    {
        public override void Handle(cClientPacketHandler Packet, cClient Client)
        {
            try
            {
                string sUsername = Packet.getBlockByIndex(2);
                string sPassword = Packet.getBlockByIndex(3);
                string[] fData = cMain.DBClass.proc_checkAccount(sUsername, sPassword).Split(new char[] { '/' });
                long UserID = Convert.ToInt32(int.Parse(fData[1]));
                int Logged = Convert.ToInt32(int.Parse(fData[7]));
                int rowstoint = Convert.ToInt32(int.Parse(fData[8]));
                string password = fData[3];
                bool rowsinbool = Convert.ToBoolean(rowstoint);
                int Acces = int.Parse(fData[5]);
                int FirstLogin = int.Parse(fData[11]);
                if (rowsinbool == false)
                {
                    Client.Send(new SP_SERVER_LIST(SP_SERVER_LIST.errorCodes.WrongUser));
                }
                else if (password != sPassword)
                {
                    Client.Send(new SP_SERVER_LIST(SP_SERVER_LIST.errorCodes.WrongPW));
                }
                else if (Logged == 1)
                {
                    Client.Send(new SP_SERVER_LIST(SP_SERVER_LIST.errorCodes.AlreadyLoggedIn));
                }
                else if (Acces < 1)
                {
                    Client.Send(new SP_SERVER_LIST(SP_SERVER_LIST.errorCodes.Banned));
                }
                else if (rowsinbool == true)
                {
                    Client.setUsername(sUsername);
                    Client.setPassword(sPassword);
                    Client.setUserID(UserID);
                    Client.setNickname(fData[4]);
                    Client.setAccesslevel(Acces);
                    if (FirstLogin == 1)
                    {
                        Client.Send(new SP_SERVER_LIST(SP_SERVER_LIST.errorCodes.Nickname));
                         }
                    else
                    {
                        Client.Send(new SP_SERVER_LIST(Client));
                        cMain.WriteLine("cWRClient", "Disposed Client from IP : [ " + Client.ClientSocket.RemoteEndPoint.ToString().Split(new char[] { ' ' })[0] + " ]");
           
                   }
                }
            }
            catch (Exception ex)
            {

            }
            
        }
    }
}

/* Copyright 2010 © by YeZZx aka Crunkx */