forked from FICTURE7/CoCSharp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCoCRemoteClient.cs
36 lines (31 loc) · 1.16 KB
/
CoCRemoteClient.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
using CoCSharp.Networking;
using System.Net.Sockets;
using CoCSharp.Server.Handlers;
using CoCSharp.Logic;
using System;
namespace CoCSharp.Server
{
public class CoCRemoteClient
{
public CoCRemoteClient(CoCServer server, Socket connection, NetworkManagerAsyncSettings settings)
{
_server = server;
Connection = connection;
Avatar = new Avatar();
NetworkManager = new NetworkManagerAsync(connection, settings);
NetworkManager.MessageReceived += OnMessageReceived;
}
public Avatar Avatar { get; set; }
public Socket Connection { get; private set; }
public NetworkManagerAsync NetworkManager { get; private set; }
private readonly CoCServer _server;
private void OnMessageReceived(object sender, MessageReceivedEventArgs e)
{
if (e.Exception != null)
Console.WriteLine("Exception occured: {0}", e.Exception.ToString());
var handler = (MessageHandler)null;
if (_server.MessageHandlers.TryGetValue(e.Message.ID, out handler))
handler(_server, this, e.Message);
}
}
}