public override void ServerSend(int connectionId, int channelId, ArraySegment <byte> segment) { // TODO: Optimize bool tryDirectConnect = directConnectModule != null; if (tryDirectConnect) { int clientID; if (connectedDirectClients.TryGetBySecond(connectionId, out clientID)) { directConnectModule.ServerSend(clientID, segment, channelId); return; } } ServerSendData(connectedRelayClients.GetBySecond(connectionId), segment, channelId); }
public override bool ServerSend(List <int> connectionIds, int channelId, ArraySegment <byte> segment) { // TODO: Optimize bool tryDirectConnect = directConnectModule != null; if (tryDirectConnect) { int clientID; if (connectedDirectClients.TryGetBySecond(connectionIds[0], out clientID)) { return(directConnectModule.ServerSend(clientID, segment, channelId)); } } ServerSendData(connectedRelayClients.GetBySecond(connectionIds[0]), segment, channelId); return(false); }
public override bool ServerSend(List <int> connectionIds, int channelId, ArraySegment <byte> segment) { // TODO: Optimize List <ushort> clients = new List <ushort>(); List <int> directClients = new List <int>(); bool tryDirectConnect = directConnectModule != null; for (int i = 0; i < connectionIds.Count; i++) { if (tryDirectConnect) { int clientID = 0; if (connectedDirectClients.TryGetBySecond(connectionIds[i], out clientID)) { directClients.Add(clientID); continue; } } clients.Add(connectedRelayClients.GetBySecond(connectionIds[i])); // Including more than 10 client ids per single packet to the relay server could get risky with MTU so less risks if we split it into chunks of 1 packet per 10 players its sending to the server if (clients.Count >= 10) { ServerSendData(clients, segment, channelId); clients.Clear(); } } if (clients.Count > 0) { ServerSendData(clients, segment, channelId); } if (directClients.Count > 0) { directConnectModule.ServerSend(directClients, segment, channelId); } return(true); }