1
0
mirror of https://github.com/lidgren/lidgren-network-gen3.git synced 2026-05-14 06:06:30 +09:00

Added LibrarySamples/EncryptionSample

This commit is contained in:
lidgren
2014-10-10 08:19:14 +00:00
parent e9b6434831
commit 7822a14526
7 changed files with 327 additions and 0 deletions

View File

@@ -0,0 +1,59 @@
using System;
using Lidgren.Network;
namespace EncryptionClient
{
class Program
{
static void Main(string[] args)
{
var config = new NetPeerConfiguration("enctest");
var client = new NetClient(config);
client.Start();
System.Threading.Thread.Sleep(100); // give server time to start up
client.Connect("localhost", 14242);
var encryption = new NetAESEncryption(client, "Hallonpalt");
// loop forever
while (true)
{
// read messages
var inc = client.ReadMessage();
if (inc != null)
{
switch (inc.MessageType)
{
case NetIncomingMessageType.DebugMessage:
case NetIncomingMessageType.WarningMessage:
case NetIncomingMessageType.VerboseDebugMessage:
case NetIncomingMessageType.ErrorMessage:
Console.WriteLine(inc.ReadString());
break;
case NetIncomingMessageType.StatusChanged:
var status = (NetConnectionStatus)inc.ReadByte();
Console.WriteLine(inc.SenderConnection + " (" + status + ") " + inc.ReadString());
break;
}
}
// if we're connected, get input and send
if (client.ServerConnection != null && client.ServerConnection.Status == NetConnectionStatus.Connected)
{
Console.WriteLine("Type a message:");
var input = Console.ReadLine();
var msg = client.CreateMessage();
msg.Write(input);
encryption.Encrypt(msg);
var ok = client.SendMessage(msg, NetDeliveryMethod.ReliableOrdered);
Console.WriteLine("Message sent: " + ok);
}
}
}
}
}