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


C# GonzoNet.NetworkClient类代码示例

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


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

示例1: OnPacket

 public override void OnPacket(NetworkClient client, ProcessedPacket packet)
 {
     var cmd = new VMNetCommand();
     try {
         using (var reader = new BinaryReader(packet)) {
             cmd.Deserialize(reader);
         }
     } catch (Exception)
     {
         ClientsToDC.Add(client);
         return;
     }
     if (cmd.Type == VMCommandType.SimJoin)
     {
         if (((VMNetSimJoinCmd)cmd.Command).Version != VMNetSimJoinCmd.CurVer)
         {
             ClientsToDC.Add(client);
             return;
         }
         lock (UIDs)
         {
             UIDs.Add(client, ((VMNetSimJoinCmd)cmd.Command).SimID);
         }
     }
     SendCommand(cmd.Command);
 }
开发者ID:Daribon,项目名称:FreeSO,代码行数:26,代码来源:VMServerDriver.cs

示例2: HandleServerChallenge

        /// <summary>
        /// Initial response from server to client.
        /// </summary>
        /// <param name="Client">A NetworkClient instance.</param>
        /// <param name="Packet">A ProcessedPacket instance.</param>
        public static void HandleServerChallenge(NetworkClient Client, ProcessedPacket Packet)
        {
            Console.WriteLine("Client receives encrypted data - test 2");

            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)PasswordHash.Length);
            Writer.Write(PasswordHash);
            Writer.Flush();

            Client.SendEncrypted(0x03, StreamToEncrypt.ToArray());

            Console.WriteLine("Test 2: passed!");
        }
开发者ID:ddfczm,项目名称:Project-Dollhouse,代码行数:39,代码来源:PacketHandlers.cs

示例3: SendCharacterCreateCity

        /// <summary>
        /// Sends a CharacterCreate packet to a CityServer.
        /// </summary>
        /// <param name="LoginArgs">Arguments used to log onto the CityServer.</param>
        /// <param name="Character">The character to create on the CityServer.</param>
        public static void SendCharacterCreateCity(NetworkClient Client, UISim Character)
        {
            PacketStream Packet = new PacketStream((byte)PacketType.CHARACTER_CREATE_CITY, 0);

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

            Writer.Write((byte)Client.ClientEncryptor.Username.Length);
            Writer.Write(Encoding.ASCII.GetBytes(Client.ClientEncryptor.Username), 0,
                Encoding.ASCII.GetBytes(Client.ClientEncryptor.Username).Length);

            Writer.Write(PlayerAccount.CityToken);
            Writer.Write(Character.Timestamp);
            Writer.Write(Character.Name);
            Writer.Write(Character.Sex);
            Writer.Write(Character.Description);
            Writer.Write((ulong)Character.HeadOutfitID);
            Writer.Write((ulong)Character.BodyOutfitID);
            Writer.Write((byte)Character.Avatar.Appearance);

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

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

示例4: OnLoginSuccessResponse

        public static void OnLoginSuccessResponse(ref NetworkClient Client, ProcessedPacket Packet)
        {
            string CacheDir = GlobalSettings.Default.DocumentsPath + "CharacterCache\\" + PlayerAccount.Username;

            if (!Directory.Exists(CacheDir))
            {
                Directory.CreateDirectory(CacheDir);

                //The charactercache didn't exist, so send the Unix epoch, which is
                //older than the server's stamp. This will cause the server to send the entire cache.
                PacketSenders.SendCharacterInfoRequest(new DateTime(1970, 1, 1, 0, 0, 0, 0).ToString(CultureInfo.InvariantCulture));
            }
            else
            {
                if (!File.Exists(CacheDir + "\\Sims.cache"))
                {
                    //The charactercache didn't exist, so send the Unix epoch, which is
                    //older than the server's stamp. This will cause the server to send the entire cache.
                    PacketSenders.SendCharacterInfoRequest(new DateTime(1970, 1, 1, 0, 0, 0, 0).ToString(CultureInfo.InvariantCulture));
                }
                else
                {
                    string LastDateCached = Cache.GetDateCached();
                    if (LastDateCached == "")
                        PacketSenders.SendCharacterInfoRequest(new DateTime(1970, 1, 1, 0, 0, 0, 0).ToString(CultureInfo.InvariantCulture));
                    else
                        PacketSenders.SendCharacterInfoRequest(LastDateCached);
                }
            }
        }
开发者ID:ddfczm,项目名称:Project-Dollhouse,代码行数:30,代码来源:PacketHandlers.cs

示例5: SendServerInfo

        /// <summary>
        /// Send information about this CityServer to the LoginServer...
        /// </summary>
        /// <param name="Client">The client connected to the LoginServer.</param>
        public static void SendServerInfo(NetworkClient Client)
        {
            PacketStream Packet = new PacketStream(0x64, 0);
            Packet.WriteByte(0x64);

            MemoryStream PacketBody = new MemoryStream();
            BinaryWriter PacketWriter = new BinaryWriter(PacketBody);

            PacketWriter.Write((string)GlobalSettings.Default.CityName);
            PacketWriter.Write((string)GlobalSettings.Default.CityDescription);
            PacketWriter.Write((string)Settings.BINDING.Address.ToString());
            PacketWriter.Write((int)Settings.BINDING.Port);
            PacketWriter.Write((byte)1); //CityInfoStatus.OK
            PacketWriter.Write((ulong)GlobalSettings.Default.CityThumbnail);
            PacketWriter.Write((string)GlobalSettings.Default.ServerID);
            PacketWriter.Write((ulong)GlobalSettings.Default.Map);
            PacketWriter.Flush();

            Packet.WriteUInt16((ushort)(PacketBody.ToArray().Length + PacketHeaders.UNENCRYPTED));

            Packet.Write(PacketBody.ToArray(), 0, (int)PacketWriter.BaseStream.Length);
            Packet.Flush();

            PacketWriter.Close();

            Client.Send(Packet.ToArray());
        }
开发者ID:Blayer98,项目名称:Project-Dollhouse,代码行数:31,代码来源:LoginPacketSenders.cs

示例6: HandleKeyFetch

        /// <summary>
        /// A cityserver requested a decryptionkey for a client!
        /// </summary>
        public static void HandleKeyFetch(NetworkClient Client, ProcessedPacket P)
        {
            string AccountName = P.ReadString();

            byte[] EncKey = new byte[1];

            foreach (NetworkClient Cl in NetworkFacade.CServerListener.Clients)
            {
                if (Cl.ClientEncryptor.Username == AccountName)
                {
                    EncKey = Cl.ClientEncryptor.GetDecryptionArgsContainer().ARC4DecryptArgs.EncryptionKey;

                    //TODO: Figure out what to do about CurrentlyActiveSim...
                    //if (Cl.CurrentlyActiveSim.CreatedThisSession)
                    {
                        //TODO: Update the DB to reflect the city that
                        //      this sim resides in.
                        //Database.UpdateCityForCharacter(Cl.CurrentlyActiveSim.Name, Client.ServerInfo.Name);
                    }
                }
            }

            PacketStream OutPacket = new PacketStream(0x01, 0x00);
            OutPacket.WriteByte((byte)0x01);
            OutPacket.WriteByte((byte)(EncKey.Length + 2));
            OutPacket.WriteByte((byte)EncKey.Length);
            OutPacket.Write(EncKey, 0, EncKey.Length);
            Client.Send(OutPacket.ToArray());

            //For now, assume client has already disconnected and doesn't need to be disconnected manually.
            NetworkFacade.CServerListener.TransferringClients.Remove(Client);
        }
开发者ID:Blayer98,项目名称:Project-Dollhouse,代码行数:35,代码来源:CityServerPacketHandlers.cs

示例7: HandlePlayerOnlineResponse

        public static void HandlePlayerOnlineResponse(NetworkClient Client, ProcessedPacket P)
        {
            byte Result = (byte)P.ReadByte();
            string Token = P.ReadString();
            //NOTE: Might have to find another way to identify a client, since two people
            //		can be on the same account from the same IP.
            string RemoteIP = P.ReadString();
            int RemotePort = P.ReadInt32();

            PacketStream Packet;
            NetworkClient FoundClient;

            switch(Result)
            {
                case 0x01:
                    Packet = new PacketStream((byte)PacketType.REQUEST_CITY_TOKEN, 0);
                    Packet.WriteString(Token);
                    FoundClient = NetworkFacade.ClientListener.GetClient(RemoteIP, RemotePort);

                    if(FoundClient != null)
                        FoundClient.SendEncrypted((byte)PacketType.REQUEST_CITY_TOKEN, Packet.ToArray());

                    break;
                case 0x02: //Write player was already online packet!
                    Packet = new PacketStream((byte)PacketType.PLAYER_ALREADY_ONLINE, 0);
                    Packet.WriteByte(0x00); //Dummy
                    FoundClient = NetworkFacade.ClientListener.GetClient(RemoteIP, RemotePort);

                    if (FoundClient != null)
                        FoundClient.SendEncrypted((byte)PacketType.PLAYER_ALREADY_ONLINE, Packet.ToArray());

                    break;
            }
        }
开发者ID:ddfczm,项目名称:Project-Dollhouse,代码行数:34,代码来源:CityServerPacketHandlers.cs

示例8: HandleBroadcastLetter

        /// <summary>
        /// Player (admin?) broadcast a letter.
        /// </summary>
        public static void HandleBroadcastLetter(NetworkClient Client, ProcessedPacket Packet)
        {
            string Subject = Packet.ReadString();
            string Msg = Packet.ReadString();

            NetworkFacade.CurrentSession.SendBroadcastLetter(Client, Subject, Msg);
        }
开发者ID:RHY3756547,项目名称:FreeSO,代码行数:10,代码来源:ClientPacketHandlers.cs

示例9: 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

示例10: 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

示例11: 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

示例12: Handle

 public static void Handle(NetworkClient Client, ProcessedPacket stream)
 {
     byte ID = (byte)stream.ReadByte();
     if (m_Handlers.ContainsKey(ID))
     {
         m_Handlers[ID].Handler(Client, stream);
     }
 }
开发者ID:Blayer98,项目名称:Project-Dollhouse,代码行数:8,代码来源:PacketHandlers.cs

示例13: HandleClientToken

        public static void HandleClientToken(NetworkClient Client, ProcessedPacket P)
        {
            ClientToken Token = new ClientToken();
            Token.ClientIP = P.ReadPascalString();
            Token.CharacterGUID = P.ReadPascalString();
            Token.Token = P.ReadPascalString();

            NetworkFacade.TransferringClients.AddItem(Token);
        }
开发者ID:Tranquill6,项目名称:Project-Dollhouse,代码行数:9,代码来源:LoginPacketHandlers.cs

示例14: ReceivedUnEncryptedPacket

        public static void ReceivedUnEncryptedPacket(NetworkClient Client, PacketStream Packet)
        {
            //NOTE: Normally, the client would only send its username, and that would be
            //      used to lookup the password from the database.
            string Password = Packet.ReadPascalString();
            Console.WriteLine("Received password from client: " + Password);

            //TODO: Client should be passed by ref?
            //ClientEncryptor must be initialized in order to decrypt encrypted messages!
            Client.ClientEncryptor = new ARC4Encryptor(Password);
        }
开发者ID:Blayer98,项目名称:Project-Dollhouse,代码行数:11,代码来源:Handlers.cs

示例15: VMClientDriver

        public VMClientDriver(string hostName, int port, OnStateChangeDelegate callback)
        {
            Commands = new Queue<VMNetCommandBodyAbstract>();
            Client = new NetworkClient(hostName, port, EncryptionMode.NoEncryption, true);

            Client.OnConnected += Client_OnConnected;
            Client.OnDisconnect += Client_OnDisconnect;
            OnStateChange += callback;
            Client.Connect(null);

            TickBuffer = new Queue<VMNetTick>();
        }
开发者ID:Daribon,项目名称:FreeSO,代码行数:12,代码来源:VMClientDriver.cs


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