Network Library Documentation
Loading...
Searching...
No Matches
ServerSendHandler Class Reference

Contains all of the methods for packet sending according to their type. More...

Static Public Member Functions

static Packet AddHmac (Packet sendPacket, int ClientNum)
 Adds HMAC to packet, returns packet with HMAC.
static byte[] GenerateHmac (Packet packet, byte[] key)
 Generates HMAC of the data with the key from argument.
static void DisconnectedUser (int clientId)
 Sends a packet to all clients to inform them that a user has disconnected.
static void LatencyToUser (int clientId, int pcktId)
 Sends a latency response packet (ping reply) to a specific client.
static void WelcomePacket (int clientId, string message)
 Sends a welcome message to a newly connected client.
static void SendHmacKeyPacket (int clientID, byte[] hmacKey)
 Sends the HMAC key to a client for securing message integrity.
static void SendAuthPacket (int clientID, string token)
 Sends an authentication token to the client.
static void SpawnUser (int clientId, ServerSideClientInstance user)
 Sends a packet to spawn a new user instance on the client side.
static void SendBandwidthReply (int clientId)
 Sends a bandwidth reply packet to the client after measurement.
static void SendThroughputReply (int clientId, int pcktId, int dataSize)
 Sends a throughput measurement result to the client.
static void SendMessage (int clientId, string message)
 Sends a private text message to a specific client.
static void SendMessageAll (int clientId, string message)
 Sends a message to all clients except the sender.
static void SendToAll (Packet sendPacket)
 Sends a packet to all connected clients.
static void SendToClient (Packet sendPacket, int clientId)
 Sends a packet to a specific client.
static void SendUpdatedTransform (int clientId, Vector3 pos, Quaternion rot)
 Sends updated transform (position and rotation) to all clients.
static void SendUpdatedAnimation (int clientId, int type, string name, float value)
 Sends updated animation data to all clients.
static void SendToAllExc (Packet sendPacket, int exceptClient)
 Sends a packet to all clients except one specified by ID.
static void UDPSendToAll (Packet sendPacket)
 Sends a packet to all clients using UDP.

Static Private Member Functions

static void UDPSendToClient (Packet sendPacket, int clientId)
 Sends a packet to a specific client using UDP.

Detailed Description

Contains all of the methods for packet sending according to their type.

Definition at line 9 of file ServerSendHandler.cs.

Member Function Documentation

◆ AddHmac()

Packet ServerSendHandler.AddHmac ( Packet sendPacket,
int ClientNum )
static

Adds HMAC to packet, returns packet with HMAC.

Value of clients HMAC key.

Definition at line 14 of file ServerSendHandler.cs.

15 {
19 byte[] hmacKey = ServerLogic.clientsList[ClientNum].tcp.hmacKey;
20 byte[] hmac = GenerateHmac(sendPacket, hmacKey);
21 sendPacket.Write(hmac);
22 return sendPacket;
23 }
void Write(string text)
Write string data.
Definition Packet.cs:44
static byte[] GenerateHmac(Packet packet, byte[] key)
Generates HMAC of the data with the key from argument.

◆ DisconnectedUser()

void ServerSendHandler.DisconnectedUser ( int clientId)
static

Sends a packet to all clients to inform them that a user has disconnected.

Definition at line 42 of file ServerSendHandler.cs.

43 {
44 Packet sendPacket = new Packet((int)Packet.ServerPackets.DisconnectUser);
45 sendPacket.Write(clientId);
46 if(ServerLogic.GetSettings().useHMAC == true)
47 {
48 sendPacket = AddHmac(sendPacket, clientId);
49 }
50 SendToAll(sendPacket);
51 }
static void SendToAll(Packet sendPacket)
Sends a packet to all connected clients.
static Packet AddHmac(Packet sendPacket, int ClientNum)
Adds HMAC to packet, returns packet with HMAC.

◆ GenerateHmac()

byte[] ServerSendHandler.GenerateHmac ( Packet packet,
byte[] key )
static

Generates HMAC of the data with the key from argument.

Uses HMACSHA256 for computing HMAC value.

Definition at line 27 of file ServerSendHandler.cs.

28 {
29 byte[] packetData = packet.ConvertToArray();
30
34 using (HMACSHA256 hmac = new HMACSHA256(key))
35 {
36 return hmac.ComputeHash(packetData);
37 }
38 }
byte[] ConvertToArray()
Definition Packet.cs:287

◆ LatencyToUser()

void ServerSendHandler.LatencyToUser ( int clientId,
int pcktId )
static

Sends a latency response packet (ping reply) to a specific client.

Definition at line 55 of file ServerSendHandler.cs.

56 {
57 Packet sendPacket = new Packet((int)Packet.ServerPackets.Latency);
58 sendPacket.Write(clientId);
59 sendPacket.Write(pcktId);
60 UDPSendToClient(sendPacket, clientId);
61 }
static void UDPSendToClient(Packet sendPacket, int clientId)
Sends a packet to a specific client using UDP.

◆ SendAuthPacket()

void ServerSendHandler.SendAuthPacket ( int clientID,
string token )
static

Sends an authentication token to the client.

Definition at line 85 of file ServerSendHandler.cs.

86 {
87 Packet sendPacket = new Packet((int)Packet.ServerPackets.AuthToken);
88 sendPacket.Write(token);
89 sendPacket.Write(clientID);
90 SendToClient(sendPacket, clientID);
91 }
static void SendToClient(Packet sendPacket, int clientId)
Sends a packet to a specific client.

◆ SendBandwidthReply()

void ServerSendHandler.SendBandwidthReply ( int clientId)
static

Sends a bandwidth reply packet to the client after measurement.

Definition at line 109 of file ServerSendHandler.cs.

110 {
111 Packet sendPacket = new Packet((int)Packet.ServerPackets.BandwidthReply);
112 sendPacket.Write(clientId);
113 if (ServerLogic.GetSettings().useHMAC == true)
114 {
115 sendPacket = AddHmac(sendPacket, clientId);
116 }
117 SendToClient(sendPacket, clientId);
118 }

◆ SendHmacKeyPacket()

void ServerSendHandler.SendHmacKeyPacket ( int clientID,
byte[] hmacKey )
static

Sends the HMAC key to a client for securing message integrity.

Definition at line 75 of file ServerSendHandler.cs.

76 {
77 Packet sendPacket = new Packet((int)Packet.ServerPackets.HmacKey);
78 sendPacket.Write(hmacKey.Length);
79 sendPacket.Write(hmacKey);
80 SendToClient(sendPacket, clientID);
81 }

◆ SendMessage()

void ServerSendHandler.SendMessage ( int clientId,
string message )
static

Sends a private text message to a specific client.

Definition at line 132 of file ServerSendHandler.cs.

133 {
134 Packet sendPacket = new Packet((int)Packet.ServerPackets.Message);
135 sendPacket.Write(message);
136 sendPacket.Write(clientId);
137 if (ServerLogic.GetSettings().useHMAC == true)
138 {
139 sendPacket = AddHmac(sendPacket, clientId);
140 }
141 SendToClient(sendPacket, clientId);
142
143 }

◆ SendMessageAll()

void ServerSendHandler.SendMessageAll ( int clientId,
string message )
static

Sends a message to all clients except the sender.

Definition at line 147 of file ServerSendHandler.cs.

148 {
149 Packet sendPacket = new Packet((int)Packet.ServerPackets.MessageAll);
150 sendPacket.Write(message);
151 sendPacket.Write(clientId);
152 SendToAllExc(sendPacket, clientId);
153
154 }
static void SendToAllExc(Packet sendPacket, int exceptClient)
Sends a packet to all clients except one specified by ID.

◆ SendThroughputReply()

void ServerSendHandler.SendThroughputReply ( int clientId,
int pcktId,
int dataSize )
static

Sends a throughput measurement result to the client.

Definition at line 122 of file ServerSendHandler.cs.

123 {
124 Packet sendPacket = new Packet((int)Packet.ServerPackets.ThroughputReply);
125 sendPacket.Write(pcktId);
126 sendPacket.Write(dataSize);
127 UDPSendToClient(sendPacket, clientId);
128 }

◆ SendToAll()

void ServerSendHandler.SendToAll ( Packet sendPacket)
static

Sends a packet to all connected clients.

Definition at line 158 of file ServerSendHandler.cs.

159 {
160 sendPacket.SizeOfDataAtStart();
161 foreach (var user in ServerLogic.clientsList)
162 {
163 ServerSideClient ConnectedClient = user.Value;
164 ConnectedClient.tcp.Send(sendPacket);
165 }
166 }
void SizeOfDataAtStart()
Definition Packet.cs:296
void Send(Packet sendPacket)
Sends a packet over the TCP stream to the connected client.
TCP tcp
TCP connection handler.

◆ SendToAllExc()

void ServerSendHandler.SendToAllExc ( Packet sendPacket,
int exceptClient )
static

Sends a packet to all clients except one specified by ID.

Definition at line 207 of file ServerSendHandler.cs.

208 {
209 sendPacket.SizeOfDataAtStart();
210 for (int i = 1; i <= ServerLogic.maxCCU; i++)
211 {
212 if (i != exceptClient)
213 {
214 ServerLogic.clientsList[i].tcp.Send(sendPacket);
215 }
216 }
217 }

◆ SendToClient()

void ServerSendHandler.SendToClient ( Packet sendPacket,
int clientId )
static

Sends a packet to a specific client.

Definition at line 170 of file ServerSendHandler.cs.

171 {
172 sendPacket.SizeOfDataAtStart();
173 ServerLogic.clientsList[clientId].tcp.Send(sendPacket);
174 }

◆ SendUpdatedAnimation()

void ServerSendHandler.SendUpdatedAnimation ( int clientId,
int type,
string name,
float value )
static

Sends updated animation data to all clients.

Definition at line 195 of file ServerSendHandler.cs.

196 {
197 Packet sendPacket = new Packet((int)Packet.ServerPackets.AnimationUpdate);
198 sendPacket.Write(clientId);
199 sendPacket.Write(type);
200 sendPacket.Write(name);
201 sendPacket.Write(value);
202 SendToAll(sendPacket);
203 }

◆ SendUpdatedTransform()

void ServerSendHandler.SendUpdatedTransform ( int clientId,
Vector3 pos,
Quaternion rot )
static

Sends updated transform (position and rotation) to all clients.

Definition at line 178 of file ServerSendHandler.cs.

179 {
180 Packet sendPacket = new Packet((int)Packet.ServerPackets.TransformUpdate);
181 sendPacket.Write(clientId);
182 sendPacket.Write(pos);
183 sendPacket.Write(rot);
184 if(ServerLogic.GetSettings().allowUDP == true)
185 {
186 UDPSendToAll(sendPacket);
187 } else
188 {
189 SendToAll(sendPacket);
190 }
191 }
static void UDPSendToAll(Packet sendPacket)
Sends a packet to all clients using UDP.

◆ SpawnUser()

void ServerSendHandler.SpawnUser ( int clientId,
ServerSideClientInstance user )
static

Sends a packet to spawn a new user instance on the client side.

Definition at line 95 of file ServerSendHandler.cs.

96 {
97 Packet sendPacket = new Packet((int)Packet.ServerPackets.SpawnUser);
98 sendPacket.Write(user.userID);
99 sendPacket.Write(user.userName);
100 if (ServerLogic.GetSettings().useHMAC == true)
101 {
102 sendPacket = AddHmac(sendPacket, clientId);
103 }
104 SendToClient(sendPacket, clientId);
105 }

◆ UDPSendToAll()

void ServerSendHandler.UDPSendToAll ( Packet sendPacket)
static

Sends a packet to all clients using UDP.

Definition at line 229 of file ServerSendHandler.cs.

230 {
231 sendPacket.SizeOfDataAtStart();
232 foreach (var user in ServerLogic.clientsList)
233 {
234 ServerSideClient ConnectedClient = user.Value;
235 ConnectedClient.udp.SendUDPData(sendPacket);
236 }
237 }
void SendUDPData(Packet SendPacket)
Sends a UDP packet to the client using the configured endpoint.
UDP udp
UDP connection handler.

◆ UDPSendToClient()

void ServerSendHandler.UDPSendToClient ( Packet sendPacket,
int clientId )
staticprivate

Sends a packet to a specific client using UDP.

Definition at line 221 of file ServerSendHandler.cs.

222 {
223 sendPacket.SizeOfDataAtStart();
224 ServerLogic.clientsList[clientId].udp.SendUDPData(sendPacket);
225 }

◆ WelcomePacket()

void ServerSendHandler.WelcomePacket ( int clientId,
string message )
static

Sends a welcome message to a newly connected client.

Definition at line 65 of file ServerSendHandler.cs.

66 {
67 Packet SendPacket = new Packet((int)Packet.ServerPackets.welcome);
68 SendPacket.Write(message);
69 SendPacket.Write(clientId);
70 SendToClient(SendPacket, clientId);
71 }