protected void InvokeTimeoutEventHandler() { Stop(); if (TimeoutEventHandler != null) { TimeoutEventHandler.Invoke(this, EventArgs.Empty); } else { showIdleMessage(); } Start(); }
public void PollEvents() { while (raiseConnectionEvent > 0) { if (connected > 0) { OnConnectionSucces?.Invoke(); } else { OnConnectionFailed?.Invoke(); } Interlocked.Exchange(ref raiseConnectionEvent, 0); } if (raiseDisconnectEvent > 0) { OnDisconnect?.Invoke(); Interlocked.Exchange(ref raiseDisconnectEvent, 0); } if (raiseTimeoutEvent > 0) { OnTimeout?.Invoke(); Interlocked.Exchange(ref raiseTimeoutEvent, 0); } while (!pendingReceiveEvents.IsEmpty) { OnReceiveData?.Invoke(pendingReceiveEvents.Dequeue()); } while (!pendingErrorEvents.IsEmpty) { OnError?.Invoke(pendingErrorEvents.Dequeue()); } while (!pendingNetEntityCreatedEvent.IsEmpty) { KeyValuePair <NetEntity, byte[]> pair = pendingNetEntityCreatedEvent.Dequeue(); OnNetEntityCreated?.Invoke(pair.Key, pair.Value); } while (!netEntityReceiveQueue.IsEmpty) { var pair = netEntityReceiveQueue.Dequeue(); OnNetEntityReceiveData?.Invoke(pair.Key, pair.Value); } }
/// <summary> /// Removes a client from the server /// </summary> /// <param name="client"></param> /// <param name="type"></param> public void RemoveClient(TCPServerClient client, TCPDisconnectType type = TCPDisconnectType.Disconnect) { if (Logging) { Logger.Write("REGION", "Method [RemoveClient]"); } if (type == TCPDisconnectType.NoHandshake) { if (Logging) { Logger.Write("INFO", "Client no handshake: " + client.UID); } OnNoHandshake?.Invoke(client); } else if (type == TCPDisconnectType.Disconnect) { if (Logging) { Logger.Write("INFO", "Client disconnect: " + client.UID); } OnDisconnected?.Invoke(client); } else if (type == TCPDisconnectType.Timeout) { if (Logging) { Logger.Write("INFO", "Client timeout: " + client.UID); } OnTimeout?.Invoke(client); } else if (type == TCPDisconnectType.Kick) { if (Logging) { Logger.Write("INFO", "Client kick: " + client.UID); } OnKick?.Invoke(client); } lock (ClientsDict) ClientsDict.Remove(client.UID); lock (ClientsList) { for (int e = ClientsList.Count - 1; e >= 0; e--) { if (ClientsList[e].UID == client.UID) { if (Logging) { Logger.Write("INFO", "Client found in ClientsList: " + client.UID); } ClientsList.RemoveAt(e); break; } } } try { client.Socket.Shutdown(SocketShutdown.Both); client.Socket.Close(); } catch (Exception e) { if (Logging) { Logger.Write("FAILED", "Socket shutdown/close", e); } } }