public static void Create <T>(AuthOpCode opCode)
            where T : AuthMessage, new()
        {
            var type = typeof(T);

            OpCodeLookup.Add(type, opCode);
            TypeLookup.Add(opCode, type);
        }
        public static AuthMessage GetMessage(AuthOpCode opCode, BinaryReader r)
        {
            var type = TypeLookup.GetValueOrDefault(opCode);

            if (type == null)
            {
                throw new NetsphereBadOpCodeException(opCode);
            }

            return((AuthMessage)Serializer.Deserialize(r, type));
        }
Beispiel #3
0
        public byte[] ServerChallange(AuthOpCode op)
        {
            byte[] bytes = Encoding.ASCII.GetBytes((this.Name + ":" + this.Password).ToUpper().ToCharArray());
            this.usernameUP = Encoding.ASCII.GetBytes(this.Name.ToUpper().ToCharArray());
            this.G          = new BigInteger(new byte[] { 7 });
            byte[] buffer2 = new byte[] { 1 };
            this.salt = new byte[0x20];
            this.b    = new byte[20];
            rand.NextBytes(this.salt);
            rand.NextBytes(this.b);
            byte[]             bs = new SHA1CryptoServiceProvider().ComputeHash(bytes, 0, bytes.Length);
            ByteArrayBuilderV2 rv = new ByteArrayBuilderV2();

            rv.Add(this.salt);
            rv.Add(bs);
            SHA1       sha2 = new SHA1CryptoServiceProvider();
            BigInteger exp  = new BigInteger(AuthServer.Utils.Reverse(sha2.ComputeHash((byte[])rv, 0, rv.Length)));
            BigInteger n    = new BigInteger(rN);

            this.v  = this.G.modPow(exp, n);
            this.rb = AuthServer.Utils.Reverse(this.b);
            this.K  = new BigInteger(new byte[] { 3 });
            BigInteger integer3 = this.K * this.v;
            BigInteger integer4 = this.G.modPow(new BigInteger(this.rb), new BigInteger(rN));
            BigInteger integer5 = integer3 + integer4;

            this.B = BigInteger.op_Modulus(integer5, new BigInteger(rN));
            this.pack.Clear();
            this.pack.Add((byte)op);
            this.pack.Add((byte)0);
            this.pack.Add((byte)0);
            this.pack.Add(AuthServer.Utils.Reverse(this.B.getBytes(0x20)));
            this.pack.Add(new byte[] { 1, 7, 0x20 });
            this.pack.Add(N);
            this.pack.Add(this.salt);
            this.pack.Add(new byte[0x10]);
            this.pack.Add((byte)0);
            return((byte[])this.pack);
        }
Beispiel #4
0
        private void PacketHandle(ClientConnection Client)
        {
            if (Client.Data.Length > 1)
            {
                AuthOpCode op = (AuthOpCode)Client.Data[0];
                Console.WriteLine(op.ToString());
                this.OutPacket.Clear();
                switch (op)
                {
                case AuthOpCode.AUTH_LOGON_CHALLENGE:
                    if (Client.Data.Length > 0x23)
                    {
                        Client.Data.Seek(11);
                        Client.Data.Get(out this.build);
                        if (this.build != 0x1992)
                        {
                            this.OutPacket.Add((byte)0);
                            this.OutPacket.Add((byte)0);
                            this.OutPacket.Add((byte)9);
                            Client.Send((byte[])this.OutPacket);
                        }
                        else
                        {
                            Client.Data.Seek(0x10);
                            Client.Data.Get(out this.ip1);
                            Client.Data.Get(out this.ip2);
                            Client.Data.Get(out this.ip3);
                            Client.Data.Get(out this.ip4);
                            this.ip = string.Concat(new object[] { Convert.ToDecimal(this.ip1), ".", Convert.ToDecimal(this.ip2), ".", Convert.ToDecimal(this.ip3), ".", Convert.ToDecimal(this.ip4) });
                            Client.Data.Get(out this.NameLen);
                            Client.Data.Get(out Client.User.Name);
                            Client.User.Name = Client.User.Name.ToLower();
                            this.DbManager.Write("UPDATE accounts SET lastip='" + this.ip + "' WHERE name='" + Client.User.Name + "'");
                            this.MySqlReader = this.DbManager.Read("SELECT password,banned,locked,online,inworld FROM accounts WHERE name='" + Client.User.Name + "'");
                            if (!this.MySqlReader.Read())
                            {
                                this.OutPacket.Add((byte)0);
                                this.OutPacket.Add((byte)0);
                                this.OutPacket.Add((byte)4);
                                Client.Send((byte[])this.OutPacket);
                                this.MySqlReader.Close();
                            }
                            else if (this.MySqlReader.GetBoolean(3) || this.MySqlReader.GetBoolean(4))
                            {
                                this.OutPacket.Add((byte)0);
                                this.OutPacket.Add((byte)0);
                                this.OutPacket.Add((byte)6);
                                Client.Send((byte[])this.OutPacket);
                                this.MySqlReader.Close();
                            }
                            else if (this.MySqlReader.GetBoolean(1))
                            {
                                this.OutPacket.Add((byte)0);
                                this.OutPacket.Add((byte)0);
                                this.OutPacket.Add((byte)3);
                                Client.Send((byte[])this.OutPacket);
                                this.MySqlReader.Close();
                            }
                            else if (this.MySqlReader.GetBoolean(2))
                            {
                                this.OutPacket.Add((byte)0);
                                this.OutPacket.Add((byte)0);
                                this.OutPacket.Add((byte)15);
                                Client.Send((byte[])this.OutPacket);
                                this.MySqlReader.Close();
                            }
                            else
                            {
                                Client.User.Password = this.MySqlReader[0].ToString();
                                this.MySqlReader.Close();
                                this.DbManager.Write("UPDATE accounts SET online=1 WHERE name='" + Client.User.Name + "'");
                                Client.Authed = true;
                                Client.Send(Client.User.ServerChallange(op));
                            }
                        }
                        break;
                    }
                    return;

                case AuthOpCode.AUTH_LOGON_PROOF:
                    Client.Send(Client.User.ServerProof(Client.Data));
                    if (Client.User.Hash != null)
                    {
                        this.DbManager.WriteSessionKey(Client.User.Name, Client.User.Hash);
                    }
                    this.DbManager.Write("UPDATE accounts SET last_access='" + DateTime.Now.ToString() + "' WHERE name='" + Client.User.Name + "'");
                    break;

                case AuthOpCode.REALM_LIST:
                    this.MySqlReader = this.DbManager.Read("SELECT * FROM realms");
                    this.r_list.LoadRealmList(this.MySqlReader);
                    this.MySqlReader.Close();
                    this.MySqlReader = this.DbManager.Read("SELECT * FROM realmcharacters WHERE accname='" + Client.User.Name + "'");
                    this.r_list.MakeList(this.MySqlReader);
                    this.MySqlReader.Close();
                    Client.Send(this.r_list.GetList());
                    break;

                default:
                    Console.WriteLine("unhandled Opcode (" + op.ToString() + ")");
                    break;
                }
                Client.MRE.Set();
            }
        }
 public NetsphereBadOpCodeException(AuthOpCode opCode)
     : base($"Bad opCode: {opCode}")
 {
 }