Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public SocketError SendPacket(uint clid, DataPacket p, DProcessRequestResultsServer handler = null)
- {
- if (clid < Clients.Count || Clients[(int)clid] == null )
- {
- Log.Post(LogMessageType.Error, "Cannot send packet to client[{0}] - client id is invalid!", clid);
- return SocketError.SocketError;
- }
- if (Protocol == null)
- {
- Log.Post(LogMessageType.CriticalError, "Cannot send packet to client[{0}] - no protocol specified!", clid);
- return SocketError.SocketError;
- }
- if (p.DataLength > Protocol.MaxPacketLength)
- {
- Log.Post(LogMessageType.CriticalError,
- "Cannot send packet to client[{0}] - packet is too big ({1} vs {2} bytes allowed by protocol)",
- clid, p.DataLength, Protocol.MaxPacketLength);
- return SocketError.SocketError;
- }
- var client = Clients[(int) clid];
- if (!client.ShouldBeActive || !client.IsActive || client.Socket == null)
- {
- Log.Post(LogMessageType.Error,
- "Failed to send packet to client[{0}] - client is now disconnecting",
- clid);
- client.ShouldBeActive = false;
- return SocketError.SocketError;
- }
- if (!RegisterAnswerHandler(p.Key, handler))
- return SocketError.SocketError;
- SocketError err;
- client.Socket.Send(p.GetBytes(), 0, DataPacket.HeaderLength, SocketFlags.None, out err);
- if (err != SocketError.Success)
- {
- Log.Post(LogMessageType.Error,
- "Failed to send packet to client[{0}] - SocketError.{1}",
- clid, err);
- }
- return err;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement