当前位置: 首页>>代码示例>>C#>>正文


C# NetworkClient.SendEncrypted方法代码示例

本文整理汇总了C#中GonzoNet.NetworkClient.SendEncrypted方法的典型用法代码示例。如果您正苦于以下问题:C# NetworkClient.SendEncrypted方法的具体用法?C# NetworkClient.SendEncrypted怎么用?C# NetworkClient.SendEncrypted使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在GonzoNet.NetworkClient的用法示例。


在下文中一共展示了NetworkClient.SendEncrypted方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: HandleLoginNotify

        public static void HandleLoginNotify(NetworkClient Client, ProcessedPacket Packet)
        {
            //Should this be stored for permanent access?
            byte[] ServerPublicKey = Packet.ReadBytes(Packet.ReadByte());
            byte[] EncryptedData = Packet.ReadBytes(Packet.ReadByte());

            AESEncryptor Enc = (AESEncryptor)Client.ClientEncryptor;
            Enc.PublicKey = ServerPublicKey;
            Client.ClientEncryptor = Enc;
            NetworkFacade.Client.ClientEncryptor = Enc;

            ECDiffieHellmanCng PrivateKey = Client.ClientEncryptor.GetDecryptionArgsContainer().AESDecryptArgs.PrivateKey;
            byte[] NOnce = Client.ClientEncryptor.GetDecryptionArgsContainer().AESDecryptArgs.NOnce;

            byte[] ChallengeResponse = StaticStaticDiffieHellman.Decrypt(PrivateKey,
                ECDiffieHellmanCngPublicKey.FromByteArray(ServerPublicKey, CngKeyBlobFormat.EccPublicBlob),
                NOnce, EncryptedData);

            MemoryStream StreamToEncrypt = new MemoryStream();
            BinaryWriter Writer = new BinaryWriter(StreamToEncrypt);

            Writer.Write((byte)ChallengeResponse.Length);
            Writer.Write(ChallengeResponse, 0, ChallengeResponse.Length);

            Writer.Write(Client.ClientEncryptor.Username);
            Writer.Write((byte)PlayerAccount.Hash.Length);
            Writer.Write(PlayerAccount.Hash);
            Writer.Flush();

            //Encrypt data using key and IV from server, hoping that it'll be decrypted correctly at the other end...
            Client.SendEncrypted((byte)PacketType.CHALLENGE_RESPONSE, StreamToEncrypt.ToArray());
        }
开发者ID:ddfczm,项目名称:Project-Dollhouse,代码行数:32,代码来源:PacketHandlers.cs

示例2: HandleChallengeResponse

        public static void HandleChallengeResponse(NetworkClient Client, ProcessedPacket P)
        {
            PacketStream OutPacket;

            if (P.DecryptedSuccessfully)
            {
                int Length = P.ReadByte();
                byte[] CResponse;

                if (P.BufferLength >= Length)
                    CResponse = P.ReadBytes(Length);
                else
                {
                    //Authentication failed, so send this packet unencrypted.
                    OutPacket = new PacketStream((byte)PacketType.LOGIN_FAILURE_CITY, 0);
                    OutPacket.WriteHeader();
                    OutPacket.WriteUInt16((ushort)(PacketHeaders.UNENCRYPTED + 1));
                    OutPacket.WriteByte(0x03); //Bad challenge response.
                    Client.Send(OutPacket.ToArray());

                    Logger.LogInfo("Sent LOGIN_FAILURE_CITY!");
                    return;
                }

                AESDecryptionArgs DecryptionArgs = Client.ClientEncryptor.GetDecryptionArgsContainer().AESDecryptArgs;

                if (DecryptionArgs.Challenge.SequenceEqual(CResponse))
                {
                    OutPacket = new PacketStream((byte)PacketType.LOGIN_SUCCESS_CITY, 0);
                    OutPacket.WriteByte(0x01);
                    Client.SendEncrypted((byte)PacketType.LOGIN_SUCCESS_CITY, OutPacket.ToArray());

                    Logger.LogInfo("Sent LOGIN_SUCCESS_CITY!");
                }
                else
                {
                    //Authentication failed, so send this packet unencrypted.
                    OutPacket = new PacketStream((byte)PacketType.LOGIN_FAILURE_CITY, 0);
                    OutPacket.WriteHeader();
                    OutPacket.WriteUInt16((ushort)(PacketHeaders.UNENCRYPTED + 1));
                    OutPacket.WriteByte(0x03); //Bad challenge response.
                    Client.Send(OutPacket.ToArray());

                    Logger.LogInfo("Sent LOGIN_FAILURE_CITY!");
                }
            }
            else
            {
                //Authentication failed, so send this packet unencrypted.
                OutPacket = new PacketStream((byte)PacketType.LOGIN_FAILURE_CITY, 0);
                OutPacket.WriteHeader();
                OutPacket.WriteUInt16((ushort)(PacketHeaders.UNENCRYPTED + 1));
                OutPacket.WriteByte(0x03); //Bad challenge response.
                Client.Send(OutPacket.ToArray());

                Debug.WriteLine("HandleChallengeResponse - decryption failed!");
                Logger.LogInfo("Sent LOGIN_FAILURE_CITY!");
            }
        }
开发者ID:RHY3756547,项目名称:FreeSO,代码行数:59,代码来源:ClientPacketHandlers.cs

示例3: RequestCityToken

 /// <summary>
 /// Requests a token from the LoginServer, that can be used to log into a CityServer.
 /// </summary>
 /// <param name="Client">A NetworkClient instance.</param>
 public static void RequestCityToken(NetworkClient Client, UISim SelectedCharacter)
 {
     PacketStream Packet = new PacketStream((byte)PacketType.REQUEST_CITY_TOKEN, 0);
     Packet.WriteString(Client.ClientEncryptor.Username);
     Packet.WriteString(SelectedCharacter.ResidingCity.UUID);
     Packet.WriteString(SelectedCharacter.GUID.ToString());
     Client.SendEncrypted((byte)PacketType.REQUEST_CITY_TOKEN, Packet.ToArray());
 }
开发者ID:RHY3756547,项目名称:FreeSO,代码行数:12,代码来源:UIPacketSenders.cs

示例4: HandleCharacterInfoRequest

        public static void HandleCharacterInfoRequest(NetworkClient Client, ProcessedPacket P)
        {
            Logger.LogInfo("Received CharacterInfoRequest!");

            DateTime Timestamp = DateTime.Parse(P.ReadPascalString());

            //Database.CheckCharacterTimestamp(Client.Username, Client, TimeStamp);

            Character[] Characters = new Character[] { };

            using (var db = DataAccess.Get())
            {
                var account = db.Accounts.GetByUsername(Client.ClientEncryptor.Username);
                Characters = db.Characters.GetForAccount((int)account.AccountID).ToArray();
            }

            if (Characters != null)
            {
                PacketStream Packet = new PacketStream((byte)PacketType.CHARACTER_LIST, 0);
                MemoryStream PacketData = new MemoryStream();
                BinaryWriter PacketWriter = new BinaryWriter(PacketData);

                /**
                 * Whats the point of checking a timestamp here? It saves a few bytes on a packet
                 * sent once per user session. Premature optimization.
                 */
                PacketWriter.Write((byte)Characters.Length);
                foreach (Character avatar in Characters)
                {
                    PacketWriter.Write((int)avatar.CharacterID);
                    PacketWriter.Write(avatar.GUID.ToString());
                    PacketWriter.Write(avatar.LastCached);
                    PacketWriter.Write(avatar.Name);
                    PacketWriter.Write(avatar.Sex);
                    PacketWriter.Write(avatar.Description);
                    PacketWriter.Write((ulong)avatar.HeadOutfitID);
                    PacketWriter.Write((ulong)avatar.BodyOutfitID);
                    PacketWriter.Write((byte)avatar.AppearanceType);
                    PacketWriter.Write((string)avatar.CityName);
                    PacketWriter.Write((ulong)avatar.CityThumb);
                    PacketWriter.Write((string)avatar.City);
                    PacketWriter.Write((ulong)avatar.CityMap);
                    PacketWriter.Write((string)avatar.CityIp);
                    PacketWriter.Write((int)avatar.CityPort);
                }

                Packet.Write(PacketData.ToArray(), 0, (int)PacketData.Length);
                PacketWriter.Close();
                Client.SendEncrypted(0x05, Packet.ToArray());
            }
            else //No characters existed for the account.
            {
                PacketStream Packet = new PacketStream(0x05, 0);
                Packet.WriteByte(0x00); //0 characters.

                Client.SendEncrypted((byte)PacketType.CHARACTER_LIST, Packet.ToArray());
            }
        }
开发者ID:Blayer98,项目名称:Project-Dollhouse,代码行数:58,代码来源:LoginPacketHandlers.cs

示例5: HandleCityToken

        /// <summary>
        /// Received client token.
        /// </summary>
        public static void HandleCityToken(NetworkClient Client, ProcessedPacket P)
        {
            try
            {
                //bool ClientAuthenticated = false;
                ClientToken TokenToRemove = new ClientToken();

                using (DataAccess db = DataAccess.Get())
                {
                    string Token = P.ReadString();
                    ClientToken Tok;

                    if (Token == string.Empty)
                        return;

                    Tok = NetworkFacade.GetClientToken(new Guid(Token));

                    if (Tok != null)
                    {
                        //ClientAuthenticated = true;
                        TokenToRemove = Tok;

                        Character Char = db.Characters.GetForCharacterGUID(new Guid(Tok.CharacterGUID));
                        if (Char != null)
                        {
                            NetworkFacade.CurrentSession.AddPlayer(Client, Char);

                            PacketStream SuccessPacket = new PacketStream((byte)PacketType.CITY_TOKEN, 0);
                            SuccessPacket.WriteByte((byte)CityTransferStatus.Success);

                            House[] Houses = NetworkFacade.CurrentSession.GetHousesInSession();
                            SuccessPacket.WriteUInt16((ushort)Houses.Length);

                            //Ho, ho, ho...
                            foreach (House Ho in Houses)
                            {
                                SuccessPacket.WriteInt32(Ho.HouseID);
                                SuccessPacket.WriteString(Ho.Name);
                                SuccessPacket.WriteUInt16((ushort)Ho.X);
                                SuccessPacket.WriteUInt16((ushort)Ho.Y);
                                SuccessPacket.WriteByte((byte)Ho.Flags); //Might have to save this as unsigned in DB?
                                SuccessPacket.WriteInt32(Ho.Cost);
                            }

                            SuccessPacket.WriteInt32(Char.Money);

                            Client.SendEncrypted((byte)PacketType.CITY_TOKEN, SuccessPacket.ToArray());
                        }
                        /*else
                        {
                            ClientAuthenticated = false;
                            break;
                        }*/
                    }

                    NetworkFacade.TransferringClients.TryRemove(out TokenToRemove);

                    //This is not really valid anymore, because if the token doesn't exist yet,
                    //the client will now receive it when it arrives - see LoginPacketHandlers.cs
                    // - HandleClientToken()
                    /*if (!ClientAuthenticated)
                    {
                        PacketStream ErrorPacket = new PacketStream((byte)PacketType.CITY_TOKEN, 0);
                        ErrorPacket.WriteByte((byte)CityTransferStatus.GeneralError);
                        Client.SendEncrypted((byte)PacketType.CITY_TOKEN, ErrorPacket.ToArray());
                    }*/
                }
            }
            catch (Exception E)
            {
                Logger.LogDebug("Exception in HandleCityToken: " + E.ToString());
                Debug.WriteLine("Exception in HandleCityToken: " + E.ToString());

                PacketStream ErrorPacket = new PacketStream((byte)PacketType.CITY_TOKEN, 0);
                ErrorPacket.WriteByte((byte)CityTransferStatus.GeneralError);
                Client.SendEncrypted((byte)PacketType.CITY_TOKEN, ErrorPacket.ToArray());
            }
        }
开发者ID:RHY3756547,项目名称:FreeSO,代码行数:81,代码来源:ClientPacketHandlers.cs

示例6: HandleCityInfoRequest

        /// <summary>
        /// Client requested information about a city.
        /// </summary>
        public static void HandleCityInfoRequest(NetworkClient Client, ProcessedPacket P)
        {
            //This packet only contains a dummy byte, don't bother reading it.
            PacketStream Packet = new PacketStream((byte)PacketType.CITY_LIST, 0);
            Packet.WriteByte((byte)NetworkFacade.CServerListener.CityServers.Count);

            if (NetworkFacade.CServerListener.CityServers.Count > 0)
            {
                lock (NetworkFacade.CServerListener.CityServers)
                {
                    foreach (CityInfo CInfo in NetworkFacade.CServerListener.CityServers)
                    {
                        Packet.WriteString(CInfo.Name);
                        Packet.WriteString(CInfo.Description);
                        Packet.WriteString(CInfo.IP);
                        Packet.WriteInt32(CInfo.Port);

                        //Hack (?) to ensure status is written correctly.
                        switch (CInfo.Status)
                        {
                            case CityInfoStatus.Ok:
                                Packet.WriteByte(1);
                                break;
                            case CityInfoStatus.Busy:
                                Packet.WriteByte(2);
                                break;
                            case CityInfoStatus.Full:
                                Packet.WriteByte(3);
                                break;
                            case CityInfoStatus.Reserved:
                                Packet.WriteByte(4);
                                break;
                        }

                        Packet.WriteUInt64(CInfo.Thumbnail);
                        Packet.WriteString(CInfo.UUID);
                        Packet.WriteUInt64(CInfo.Map);
                    }
                }
            }

            Client.SendEncrypted((byte)PacketType.CITY_LIST, Packet.ToArray());
        }
开发者ID:RHY3756547,项目名称:FreeSO,代码行数:46,代码来源:LoginPacketHandlers.cs

示例7: HandleCharacterInfoRequest

        /// <summary>
        /// Client requested information about its characters.
        /// </summary>
        public static void HandleCharacterInfoRequest(NetworkClient Client, ProcessedPacket P)
        {
            Logger.LogInfo("Received CharacterInfoRequest!");

            string DateTimeStr = P.ReadString();
            DateTime Timestamp;

            if (DateTimeStr != string.Empty)
                Timestamp = DateTime.Parse(DateTimeStr);
            else
            {
                //Unix epoch
                Timestamp = new DateTime(1970, 1, 1, 0, 0, 1);
            }

            Character[] Characters = new Character[] { };

            using (var db = DataAccess.Get())
            {
                var account = db.Accounts.GetByUsername(Client.ClientEncryptor.Username);
                Characters = db.Characters.GetForAccount((int)account.AccountID).ToArray();
            }

            int NumChars = 0, NewChars = 0;

            if (Characters != null)
            {
                PacketStream Packet = new PacketStream((byte)PacketType.CHARACTER_LIST, 0);
                MemoryStream PacketData = new MemoryStream();
                BinaryWriter PacketWriter = new BinaryWriter(PacketData);

                NumChars = Characters.Length;

                foreach (Character avatar in Characters)
                {
                    //Zero means same, less than zero means T1 is earlier than T2, more than zero means T1 is later.
                    if (DateTime.Compare(Timestamp, avatar.LastCached) < 0)
                    {
                        NewChars++;

                        PacketWriter.Write((int)avatar.CharacterID);
                        PacketWriter.Write(avatar.GUID.ToString());
                        PacketWriter.Write(avatar.LastCached.ToString("yyyy.MM.dd hh:mm:ss",
                            CultureInfo.InvariantCulture));
                        PacketWriter.Write(avatar.Name);
                        PacketWriter.Write(avatar.Sex);
                        PacketWriter.Write(avatar.Description);
                        PacketWriter.Write((ulong)avatar.HeadOutfitID);
                        PacketWriter.Write((ulong)avatar.BodyOutfitID);
                        PacketWriter.Write((byte)avatar.AppearanceType);
                        PacketWriter.Write((string)avatar.CityName);
                        PacketWriter.Write((ulong)avatar.CityThumb);
                        PacketWriter.Write((string)avatar.City);
                        PacketWriter.Write((ulong)avatar.CityMap);
                        PacketWriter.Write((string)avatar.CityIp);
                        PacketWriter.Write((int)avatar.CityPort);
                        PacketWriter.Write((int)avatar.Money);
                    }
                }

                //NOTE: If Characters != null, but no chars were new, NumChars will be however many characters,
                //      and NewChars will be 0.

                Packet.WriteByte((byte)NumChars);
                Packet.WriteByte((byte)NewChars);
                Packet.Write(PacketData.ToArray(), 0, (int)PacketData.Length);
                PacketWriter.Close();
                Client.SendEncrypted((byte)PacketType.CHARACTER_LIST, Packet.ToArray());
            }
            else //No characters existed for the account.
            {
                PacketStream Packet = new PacketStream(0x05, 0);
                Packet.WriteByte((byte)NumChars); //0 characters.
                Packet.WriteByte((byte)NewChars); //0 new characters.

                Client.SendEncrypted((byte)PacketType.CHARACTER_LIST, Packet.ToArray());
            }
        }
开发者ID:RHY3756547,项目名称:FreeSO,代码行数:81,代码来源:LoginPacketHandlers.cs

示例8: HandleCharacterCreate

        /// <summary>
        /// Client created a character!
        /// </summary>
        public static void HandleCharacterCreate(NetworkClient Client, ProcessedPacket P)
        {
            Logger.LogInfo("Received CharacterCreate!");

            string AccountName = SanitizeAccount(P.ReadString());
            //Need to be variable length, because the success packet contains a token.
            PacketStream CCStatusPacket = new PacketStream((byte)PacketType.CHARACTER_CREATION_STATUS, 0);

            using (var db = DataAccess.Get())
            {
                Account Acc = db.Accounts.GetByUsername(AccountName);

                if (Acc.NumCharacters >= 3)
                {
                    CCStatusPacket.WriteByte((int)LoginDataModel.Entities.CharacterCreationStatus.ExceededCharacterLimit);
                    Client.SendEncrypted(CCStatusPacket.PacketID, CCStatusPacket.ToArray());

                    return;
                }

                //TODO: Send GUID to client...
                var Char = new Character();
                string LastCached = P.ReadString();
                if (LastCached == string.Empty)
                {
                    //TODO: Proper error...
                    CCStatusPacket.WriteByte((int)LoginDataModel.Entities.CharacterCreationStatus.NameAlreadyExisted);
                    Client.SendEncrypted(CCStatusPacket.PacketID, CCStatusPacket.ToArray());
                    return;
                }

                Char.LastCached = ProtoHelpers.ParseDateTime(LastCached);
                Char.Name = P.ReadString();
                Char.Sex = P.ReadString();
                Char.Description = P.ReadString();
                Char.GUID = Guid.NewGuid();
                Char.HeadOutfitID = (long)P.ReadUInt64();
                Char.BodyOutfitID = (long)P.ReadUInt64();
                Char.AccountID = Acc.AccountID;
                Char.AppearanceType = P.ReadByte();
                Char.CityName = P.ReadString();
                Char.CityThumb = (long)P.ReadUInt64();
                Char.City = P.ReadString();
                Char.CityMap = (long)P.ReadUInt64();
                Char.CityIp = P.ReadString();
                Char.CityPort = P.ReadInt32();
                Char.Money = NetworkFacade.INITIAL_MONEY;

                //These are going into DB, so be nazi. Sieg heil!
                if (Char.Name == string.Empty || Char.Sex == string.Empty ||
                    Char.Description == string.Empty)
                {
                    CCStatusPacket.WriteByte((int)LoginDataModel.Entities.CharacterCreationStatus.NameAlreadyExisted);
                    Client.SendEncrypted(CCStatusPacket.PacketID, CCStatusPacket.ToArray());
                    return;
                }

                var status = db.Characters.CreateCharacter(Char);

                switch (status)
                {
                    case LoginDataModel.Entities.CharacterCreationStatus.NameAlreadyExisted:
                        CCStatusPacket.WriteByte((int)LoginDataModel.Entities.CharacterCreationStatus.NameAlreadyExisted);
                        Client.SendEncrypted(CCStatusPacket.PacketID, CCStatusPacket.ToArray());
                        break;
                    case LoginDataModel.Entities.CharacterCreationStatus.NameTooLong:
                        CCStatusPacket.WriteByte((int)LoginDataModel.Entities.CharacterCreationStatus.NameTooLong);
                        Client.SendEncrypted(CCStatusPacket.PacketID, CCStatusPacket.ToArray());
                        break;
                    case LoginDataModel.Entities.CharacterCreationStatus.Success:
                        Guid Token = Guid.NewGuid();

                        //This actually updates the record, not sure how.
                        Acc.NumCharacters++;

                        //THIS NEEDS TO HAPPEN FIRST FOR CITY SERVER AUTHENTICATION TO WORK!
                        CityInfo CServer = NetworkFacade.CServerListener.GetCityServer(Char.City);

                        //Just in case...
                        if (CServer != null)
                        {
                            PacketStream CServerPacket = new PacketStream(0x01, 0);
                            CServerPacket.WriteHeader();

                            ushort PacketLength = (ushort)(PacketHeaders.UNENCRYPTED + 1 + 4 + (Client.RemoteIP.Length + 1)
                                + 4 + (Char.GUID.ToString().Length + 1) + (Token.ToString().Length + 1));
                            CServerPacket.WriteUInt16(PacketLength);

                            CServerPacket.WriteByte(1); //CharacterCreate = true
                            CServerPacket.WriteInt32(Acc.AccountID);
                            CServerPacket.WriteString(Client.RemoteIP);
                            CServerPacket.WriteInt32(Client.RemotePort);
                            CServerPacket.WriteString(Char.GUID.ToString());
                            CServerPacket.WriteString(Token.ToString(""));
                            CServer.Client.Send(CServerPacket.ToArray());
                        }

//.........这里部分代码省略.........
开发者ID:RHY3756547,项目名称:FreeSO,代码行数:101,代码来源:LoginPacketHandlers.cs

示例9: HandleCharacterCreate

        public static void HandleCharacterCreate(NetworkClient Client, ProcessedPacket P)
        {
            Logger.LogInfo("Received CharacterCreate!");

            string AccountName = SanitizeAccount(P.ReadPascalString());

            using (var db = DataAccess.Get())
            {
                Account Acc = db.Accounts.GetByUsername(AccountName);

                //TODO: Send GUID to client...
                SimBase Char = new SimBase(Guid.NewGuid());
                Char.Timestamp = P.ReadPascalString();
                Char.Name = P.ReadPascalString();
                Char.Sex = P.ReadPascalString();
                Char.Description = P.ReadPascalString();
                Char.HeadOutfitID = P.ReadUInt64();
                Char.BodyOutfitID = P.ReadUInt64();
                Char.Appearance = (AppearanceType)P.ReadByte();
                Char.ResidingCity = new CityInfo(P.ReadPascalString(), "", P.ReadUInt64(), P.ReadPascalString(),
                    P.ReadUInt64(), P.ReadPascalString(), P.ReadInt32());
                Char.CreatedThisSession = true;

                var characterModel = new Character();
                characterModel.Name = Char.Name;
                characterModel.Sex = Char.Sex;
                characterModel.Description = Char.Description;
                characterModel.LastCached = Char.Timestamp;
                characterModel.GUID = Char.GUID;
                characterModel.HeadOutfitID = (long)Char.HeadOutfitID;
                characterModel.BodyOutfitID = (long)Char.BodyOutfitID;
                characterModel.AccountID = Acc.AccountID;
                characterModel.AppearanceType = (int)Char.Appearance;
                characterModel.City = Char.ResidingCity.UUID;
                characterModel.CityName = Char.ResidingCity.Name;
                characterModel.CityThumb = (long)Char.ResidingCity.Thumbnail;
                characterModel.CityMap = (long)Char.ResidingCity.Map;
                characterModel.CityIp = Char.ResidingCity.IP;
                characterModel.CityPort = Char.ResidingCity.Port;

                var status = db.Characters.CreateCharacter(characterModel);
                //Need to be variable length, because the success packet contains a token.
                PacketStream CCStatusPacket = new PacketStream((byte)PacketType.CHARACTER_CREATION_STATUS, 0);

                switch (status)
                {
                    case LoginDataModel.Entities.CharacterCreationStatus.NameAlreadyExisted:
                        CCStatusPacket.WriteByte((int)LoginDataModel.Entities.CharacterCreationStatus.NameAlreadyExisted);
                        Client.SendEncrypted(CCStatusPacket.PacketID, CCStatusPacket.ToArray());
                        break;
                    case LoginDataModel.Entities.CharacterCreationStatus.ExceededCharacterLimit:
                        CCStatusPacket.WriteByte((int)LoginDataModel.Entities.CharacterCreationStatus.ExceededCharacterLimit);
                        Client.SendEncrypted(CCStatusPacket.PacketID, CCStatusPacket.ToArray());
                        break;
                    case LoginDataModel.Entities.CharacterCreationStatus.Success:
                        CCStatusPacket.WriteByte((int)LoginDataModel.Entities.CharacterCreationStatus.Success);
                        CCStatusPacket.WritePascalString(Char.GUID.ToString());
                        Guid Token = Guid.NewGuid();
                        CCStatusPacket.WritePascalString(Token.ToString());
                        Client.SendEncrypted(CCStatusPacket.PacketID, CCStatusPacket.ToArray());

                        foreach (CityServerClient CServer in NetworkFacade.CServerListener.CityServers)
                        {
                            if (CServer.ServerInfo.UUID == Char.ResidingCity.UUID)
                            {
                                PacketStream CServerPacket = new PacketStream(0x01, 0);
                                CServerPacket.WriteHeader();

                                ushort PacketLength = (ushort)(PacketHeaders.UNENCRYPTED + 4 + (Client.RemoteIP.Length + 1)
                                    + (Char.GUID.ToString().Length + 1) + (Token.ToString().Length + 1));
                                CServerPacket.WriteUInt16(PacketLength);

                                CServerPacket.WriteInt32(Acc.AccountID);
                                CServerPacket.WritePascalString(Client.RemoteIP);
                                CServerPacket.WritePascalString(Char.GUID.ToString());
                                CServerPacket.WritePascalString(Token.ToString());
                                CServer.Send(CServerPacket.ToArray());

                                break;
                            }
                        }

                        break;
                }
            }

            //Client was modified, so update it.
            NetworkFacade.ClientListener.UpdateClient(Client);
        }
开发者ID:Blayer98,项目名称:Project-Dollhouse,代码行数:89,代码来源:LoginPacketHandlers.cs

示例10: SendLotPurchaseRequest

 /// <summary>
 /// Sends a request to purchase a lot.
 /// </summary>
 /// <param name="Client">NetworkClient instance connected to city server.</param>
 /// <param name="X">X-coordinate of lot.</param>
 /// <param name="Y">Y-coordinate of lot.</param>
 public static void SendLotPurchaseRequest(NetworkClient Client, short X, short Y)
 {
     PacketStream Packet = new PacketStream((byte)PacketType.LOT_PURCHASE_REQUEST, 0);
     Packet.WriteUInt16((ushort)X);
     Packet.WriteUInt16((ushort)Y);
     Client.SendEncrypted((byte)PacketType.LOT_PURCHASE_REQUEST, Packet.ToArray());
 }
开发者ID:RHY3756547,项目名称:FreeSO,代码行数:13,代码来源:UIPacketSenders.cs

示例11: SendLetter

 public static void SendLetter(NetworkClient Client, string Msg, string Subject, string GUID)
 {
     PacketStream Packet = new PacketStream((byte)PacketType.PLAYER_SENT_LETTER, 0);
     Packet.WriteString(GUID);
     Packet.WriteString(Subject);
     Packet.WriteString(Msg);
     Client.SendEncrypted((byte)PacketType.PLAYER_SENT_LETTER, Packet.ToArray());
 }
开发者ID:RHY3756547,项目名称:FreeSO,代码行数:8,代码来源:UIPacketSenders.cs

示例12: SendCityToken

        /// <summary>
        /// Sends a token to a CityServer, as received by a LoginServer.
        /// </summary>
        /// <param name="Client">A NetworkClient instance.</param>
        public static void SendCityToken(NetworkClient Client)
        {
            PacketStream Packet = new PacketStream((byte)PacketType.CITY_TOKEN, 0);

            MemoryStream PacketData = new MemoryStream();
            BinaryWriter Writer = new BinaryWriter(PacketData);

            Writer.Write(PlayerAccount.CityToken);

            Packet.WriteBytes(PacketData.ToArray());
            Writer.Close();

            Client.SendEncrypted((byte)PacketType.CITY_TOKEN, Packet.ToArray());
        }
开发者ID:RHY3756547,项目名称:FreeSO,代码行数:18,代码来源:UIPacketSenders.cs

示例13: OnLoginNotifyCity

        /// <summary>
        /// Received initial packet from CityServer.
        /// </summary>
        public static void OnLoginNotifyCity(NetworkClient Client, ProcessedPacket Packet)
        {
            LogThis.Log.LogThis("Received OnLoginNotifyCity!", LogThis.eloglevel.info);

            //Should this be stored for permanent access?
            byte[] ServerPublicKey = Packet.ReadBytes(Packet.ReadByte());
            byte[] EncryptedData = Packet.ReadBytes(Packet.ReadByte());

            //            lock (Client.ClientEncryptor)
            //            {
            //                AESEncryptor Enc = (AESEncryptor)Client.ClientEncryptor;
            //                Enc.PublicKey = ServerPublicKey;
            //                Client.ClientEncryptor = Enc;
            //                lock (NetworkFacade.Client)
            //                    NetworkFacade.Client.ClientEncryptor = Enc;
            //            }

            //            ECDiffieHellmanCng PrivateKey = Client.ClientEncryptor.GetDecryptionArgsContainer().AESDecryptArgs.PrivateKey;
            //            byte[] NOnce = Client.ClientEncryptor.GetDecryptionArgsContainer().AESDecryptArgs.NOnce;

            //            byte[] ChallengeResponse = StaticStaticDiffieHellman.Decrypt(PrivateKey,
            //                ECDiffieHellmanCngPublicKey.FromByteArray(ServerPublicKey, CngKeyBlobFormat.EccPublicBlob),
            //                NOnce, EncryptedData);

            MemoryStream StreamToEncrypt = new MemoryStream();
            BinaryWriter Writer = new BinaryWriter(StreamToEncrypt);

            //            Writer.Write((byte)ChallengeResponse.Length);
            //            Writer.Write(ChallengeResponse, 0, ChallengeResponse.Length);
            Writer.Flush();

            //Encrypt data using key and IV from server, hoping that it'll be decrypted correctly at the other end...
            Client.SendEncrypted((byte)PacketType.CHALLENGE_RESPONSE, StreamToEncrypt.ToArray());
        }
开发者ID:RHY3756547,项目名称:FreeSO,代码行数:37,代码来源:UIPacketHandlers.cs

示例14: HandleLotPurchaseRequest

        /// <summary>
        /// A player sent a lot purchase request!
        /// </summary>
        public static void HandleLotPurchaseRequest(NetworkClient Client, ProcessedPacket Packet)
        {
            int X = Packet.ReadUInt16();
            int Y = Packet.ReadUInt16();

            if (!NetworkFacade.CurrentSession.IsLotOccupied(X, Y))
            {
                using (DataAccess db = DataAccess.Get())
                {
                    //TODO: Enable this later??
                    //if (db.Houses.GetForPosition(X, Y).HouseID != 0)
                    //{
                        if (NetworkFacade.CurrentTerrain.IsLandBuildable(X, Y))
                        {
                            Guid CharGuid = NetworkFacade.CurrentSession.GetPlayer(Client).GUID;
                            Character Char = db.Characters.GetForCharacterGUID(CharGuid);

                            if (Char.Money >= NetworkFacade.LOT_COST)
                            {
                                Char.HouseHouse = new House();
                                Char.HouseHouse.Name = "Yolo"; //TODO: Fixme
                                Char.HouseHouse.X = X;
                                Char.HouseHouse.Y = Y;

                                switch(db.Houses.CreateHouse(Char.HouseHouse))
                                {
                                    case CityDataModel.Entities.HouseCreationStatus.GeneralError:
                                        PacketStream UnbuildablePacket = new PacketStream((byte)PacketType.LOT_UNBUILDABLE, 0);
                                        UnbuildablePacket.WriteByte(0x00);
                                        Client.SendEncrypted((byte)PacketType.LOT_UNBUILDABLE, UnbuildablePacket.ToArray());
                                        return;
                                    case CityDataModel.Entities.HouseCreationStatus.NameTooLong:
                                        PacketStream NameTooLongPacket = new PacketStream((byte)PacketType.LOT_NAME_TOO_LONG, 0);
                                        NameTooLongPacket.WriteByte(0x00);
                                        Client.SendEncrypted((byte)PacketType.LOT_NAME_TOO_LONG, NameTooLongPacket.ToArray());
                                        return;
                                    default:
                                        break;
                                }

                                Char.Money -= NetworkFacade.LOT_COST;

                                PacketStream SuccessPacket = new PacketStream((byte)PacketType.LOT_PURCHASE_SUCCESSFUL, 0);
                                SuccessPacket.WriteInt32(Char.Money);
                                Client.SendEncrypted((byte)PacketType.LOT_PURCHASE_SUCCESSFUL, SuccessPacket.ToArray());
                            }
                            else
                            {
                                PacketStream OutOfMoneyPacket = new PacketStream((byte)PacketType.LOT_PURCHASE_FAILED, 0);
                                OutOfMoneyPacket.WriteByte(0x00); //Out of money
                                Client.SendEncrypted((byte)PacketType.LOT_PURCHASE_FAILED, OutOfMoneyPacket.ToArray());
                            }
                        }
                        else
                        {
                            PacketStream UnbuildablePacket = new PacketStream((byte)PacketType.LOT_UNBUILDABLE, 0);
                            UnbuildablePacket.WriteByte(0x00);
                            Client.SendEncrypted((byte)PacketType.LOT_UNBUILDABLE, UnbuildablePacket.ToArray());
                        }
                    }
                //}
            }
            else
            {
                PacketStream OccupiedPacket = new PacketStream((byte)PacketType.LOT_PURCHASE_OCCUPIED, 0);
                OccupiedPacket.WriteByte(0x00);
                Client.SendEncrypted((byte)PacketType.LOT_PURCHASE_OCCUPIED, OccupiedPacket.ToArray());
            }
        }
开发者ID:RHY3756547,项目名称:FreeSO,代码行数:72,代码来源:ClientPacketHandlers.cs

示例15: HandleLotCostRequest

        /// <summary>
        /// Player requested the cost of a lot.
        /// </summary>
        public static void HandleLotCostRequest(NetworkClient Client, ProcessedPacket Packet)
        {
            ushort X = Packet.ReadUInt16();
            ushort Y = Packet.ReadUInt16();
            int LotID;
            string LotName;

            using (DataAccess db = DataAccess.Get())
            {
                LotID = db.Houses.GetForPosition(X, Y).HouseID;
                LotName = db.Houses.GetForPosition(X, Y).Name;
            }

            PacketStream LotCostPacket = new PacketStream((byte)PacketType.LOT_PURCHASE_OCCUPIED, 0);
            LotCostPacket.WriteUInt16(X);
            LotCostPacket.WriteUInt16(Y);
            LotCostPacket.WriteInt32(LotID);
            LotCostPacket.WriteString(LotName);

            byte Flags = 0;

            using (DataAccess db = DataAccess.Get())
            {
                if (db.Houses.GetForPosition(X, Y).HouseID == 0)
                {
                    if (!NetworkFacade.CurrentSession.IsLotOccupied(X, Y))
                    {
                        ProtoHelpers.SetBit(ref Flags, 0, false); //Online.
                        ProtoHelpers.SetBit(ref Flags, 1, false); //Spotlight, this will have to be checked against DB.
                        ProtoHelpers.SetBit(ref Flags, 2, false); //Locked - is the house locked for public access?
                        ProtoHelpers.SetBit(ref Flags, 3, false); //Occupied.
                        LotCostPacket.WriteByte(Flags);
                        LotCostPacket.WriteInt32(NetworkFacade.LOT_COST); //TODO: Figure out a way to deal with this...
                    }
                }
                else
                {
                    if (NetworkFacade.CurrentSession.IsLotOccupied(X, Y))
                    {
                        ProtoHelpers.SetBit(ref Flags, 0, true);  //Online.
                        ProtoHelpers.SetBit(ref Flags, 1, false); //Spotlight, this will have to be checked against DB.
                        ProtoHelpers.SetBit(ref Flags, 2, false); //Locked - is the house locked for public access?
                        ProtoHelpers.SetBit(ref Flags, 3, true);  //Occupied.
                        LotCostPacket.WriteByte(Flags);
                        LotCostPacket.WriteInt32(0);
                    }
                    else if (!NetworkFacade.CurrentSession.IsLotOccupied(X, Y))
                    {
                        ProtoHelpers.SetBit(ref Flags, 0, false); //Online.
                        ProtoHelpers.SetBit(ref Flags, 1, false); //Spotlight, this will have to be checked against DB.
                        ProtoHelpers.SetBit(ref Flags, 2, false); //Locked - is the house locked for public access?
                        ProtoHelpers.SetBit(ref Flags, 3, true);  //Occupied.
                        LotCostPacket.WriteByte(Flags);
                        LotCostPacket.WriteInt32(0);
                    }
                }
            }

            Client.SendEncrypted((byte)PacketType.LOT_COST, LotCostPacket.ToArray());
        }
开发者ID:RHY3756547,项目名称:FreeSO,代码行数:63,代码来源:ClientPacketHandlers.cs


注:本文中的GonzoNet.NetworkClient.SendEncrypted方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。