public Player(Socket ext, MCFirewall m_fwl) { fwl = m_fwl; externalSock = ext; ip = IPAddress.Parse(((IPEndPoint)externalSock.RemoteEndPoint).Address.ToString()).ToString(); if (ip == "72.52.102.33" || ip == "77.92.75.135") { Program.AddRTLine(Color.Black, "Heartbeat from ServerChecker: IP = " + ip + "\r\n", true); this.Disconnect(false); return; } if (Program.bannedIPs.Contains(ip)) { this.Disconnect("You're banned!"); return; } foreach (string bannedIP in Program.bannedIPs) { if (bannedIP[bannedIP.Length - 1] == '.') //Is a range ban^^ { if (ip.StartsWith(bannedIP)) { this.Disconnect("You're banned!"); return; } } } internalSock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); internalSock.Connect("127.0.0.1", fwl.intport); fwl.players.Add(this); internalSock.SendTimeout = 30000; internalSock.ReceiveTimeout = 30000; externalSock.SendTimeout = 30000; externalSock.ReceiveTimeout = 30000; internalThread = new Thread(new ThreadStart(InternalThread)); externalThread = new Thread(new ThreadStart(ExternalThread)); pingThread = new Thread(new ThreadStart(PingThread)); internalThread.Start(); externalThread.Start(); pingThread.Start(); Program.AddRTLine(Color.Black, "IP " + ip + " connected!\r\n", true); }
static void minecraftServer_ErrorDataReceived(object sender, DataReceivedEventArgs e) { if (e.Data == null) return; try { bool dontaddline = false; Color col = Color.Black; string line = e.Data.Trim(); if (line == null) return; int pos1 = line.IndexOf('['); if (pos1 < 0) return; int pos2 = line.IndexOf(']', pos1); if (pos2 < 0) return; pos1++; string type = line.Substring(pos1, pos2 - pos1).Trim().ToLower(); string msg = line.Substring(pos2 + 2).Trim(); switch (type) { case "info": col = Color.Black; if (msg == "Done! For help, type \"help\" or \"?\"") { minecraftFirewall = new MCFirewall(); serverStatus = "Running"; if (!consoleOnly) { mainFrm.lblStatus.Invoke(new MethodInvoker(delegate() { mainFrm.lblStatus.ForeColor = Color.Green; mainFrm.lblStatus.Text = "Running"; })); } serverFullyOnline = true; } break; case "warning": col = Color.DarkRed; break; case "severe": case "error": col = Color.Red; break; } if (!dontaddline) AddRTLine(col, line + "\r\n", false); } catch (Exception ex) { AddRTLine(Color.Red, "Critical error in StdErr reading: " + ex.ToString() + "\r\n", true); } }