本文整理汇总了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);
}
示例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!");
}
示例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());
}
示例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);
}
}
}
示例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());
}
示例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);
}
示例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;
}
}
示例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);
}
示例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());
}
示例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!");
}
}
示例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());
}
示例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);
}
}
示例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);
}
示例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);
}
示例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>();
}