/// <summary> /// Removes a snake /// </summary> public void Remove(KickCode kickCode) { StopListeningForData(); length = 0; snakeList.Remove(this); Util.Form.onlinePlayers.Invoke((MethodInvoker) delegate { Util.Form.onlinePlayers.Text = Convert.ToString(Convert.ToInt32(Util.Form.onlinePlayers.Text) - 1); }); // Remove snake from online list string ipAddress = ""; for (int i = 0; i < snakeList.Count; i++) { ipAddress = ipAddress + ip + "\r\n"; } Util.Form.setOnlineSnakes(ipAddress); Util.RemoveId(id); // Send disconnect cause if (kickCode != KickCode.NONE) { try { GetClient().Send(new byte[] { 0, (byte)kickCode }); } catch (SocketException) { return; } } try { GetClient().Shutdown(SocketShutdown.Both); GetClient().Disconnect(true); } catch (SocketException) { } Util.log("Snake disconnected from " + ip); }
/// <summary> /// Kick a snake /// </summary> internal void Kick(KickCode reason) { Remove(reason); }