-
Notifications
You must be signed in to change notification settings - Fork 1
/
DemoServerApplication.cs
49 lines (41 loc) · 1.4 KB
/
DemoServerApplication.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
37
38
39
40
41
42
43
44
45
46
47
48
49
using UnityEngine;
using UnityGameServer;
namespace Demo
{
/// <summary>
/// Demo of a server application.
/// </summary>
public class DemoServerApplication : BaseServerApplication
{
protected override void OnInitialize()
{
Logger.Log("Demo Server Initialized!", Color.black, GetType().ToString());
}
protected override void OnClientConnect(NetworkServer.IClient client)
{
Debug.Log($"A client has connect with Id {client.Id}");
}
protected override void OnClientDisconnect(NetworkServer.IClient client)
{
Debug.Log($"A client has disconnect with Id {client.Id}");
}
protected override void OnClientReceivedPacket(NetworkServer.IClient client, Packet packet)
{
// Debug.Log($"The client {client.Id} has sent a message, id: {packet.Id}");
if (packet.Id == PacketId.TestPacket)
{
Debug.Log($"The client {client.Id} has sent a test message, msg: {packet.ReadString()}");
}
}
#region Test
[Header("Demo Test"), SerializeField] string testMessage;
[Button]
void SendTestMessage()
{
var packet = new Packet(PacketId.TestPacket);
packet.Write(testMessage);
NetworkServer.SendTcpDataToAll(packet);
}
#endregion
}
}