public static void OnSocketReset(ServerSock socket)
 {
     if (ServerHooks.SocketReset != null)
     {
         ServerHooks.SocketReset(socket);
     }
 }
 public static bool OnSendBytes(ServerSock socket, byte[] buffer, int offset, int count)
 {
     if (NetHooks.SendBytes == null)
     {
         return false;
     }
     HandledEventArgs handledEventArgs = new HandledEventArgs();
     NetHooks.SendBytes(socket, buffer, offset, count, handledEventArgs);
     return handledEventArgs.Handled;
 }
Beispiel #3
0
 public static void Init()
 {
     for (int i = 0; i < 10; i++)
     {
         if (i < 9)
         {
             serverSock[i] = new ServerSock();
             serverSock[i].tcpClient.NoDelay = true;
         }
         NetMessage.buffer[i]        = new messageBuffer();
         NetMessage.buffer[i].whoAmI = i;
     }
     clientSock.tcpClient.NoDelay = true;
 }
 public static void SendBytes(ServerSock sock, byte[] buffer, int offset, int count, AsyncCallback callback, object state)
 {
     try
     {
         if (ServerApi.Hooks.InvokeNetSendBytes(sock, buffer, offset, count))
         {
             return;
         }
         if (Main.runningMono)
             sock.networkStream.Write(buffer, offset, count);
         else
             sock.networkStream.BeginWrite(buffer, offset, count, callback, state);
     }
     catch (Exception e)
     {
         sock.kill = true;
     }
 }
Beispiel #5
0
 public static void ServerLoop(object threadContext)
 {
     if (Main.rand == null)
     {
         Main.rand = new Random((int)DateTime.Now.Ticks);
     }
     if (WorldGen.genRand == null)
     {
         WorldGen.genRand = new Random((int)DateTime.Now.Ticks);
     }
     Main.myPlayer   = 8;
     serverIP        = IPAddress.Any;
     serverListenIP  = serverIP;
     Main.menuMode   = 14;
     Main.statusText = "Starting server...";
     Main.netMode    = 2;
     disconnect      = false;
     for (int i = 0; i < 9; i++)
     {
         serverSock[i] = new ServerSock();
         serverSock[i].Reset();
         serverSock[i].whoAmI            = i;
         serverSock[i].tcpClient         = new TcpClient();
         serverSock[i].tcpClient.NoDelay = true;
         serverSock[i].readBuffer        = new byte[0x400];
         serverSock[i].writeBuffer       = new byte[0x400];
     }
     tcpListener = new TcpListener(serverListenIP, serverPort);
     try
     {
         tcpListener.Start();
     }
     catch (Exception exception)
     {
         Main.menuMode   = 15;
         Main.statusText = exception.ToString();
         disconnect      = true;
     }
     if (!disconnect)
     {
         ThreadPool.QueueUserWorkItem(new WaitCallback(Netplay.ListenForClients), 1);
         Main.statusText = "Server started";
     }
     while (!disconnect)
     {
         if (stopListen)
         {
             int num2 = -1;
             for (int m = 0; m < 8; m++)
             {
                 if (!serverSock[m].tcpClient.Connected)
                 {
                     num2 = m;
                     break;
                 }
             }
             if (num2 >= 0)
             {
                 tcpListener.Start();
                 stopListen = false;
                 ThreadPool.QueueUserWorkItem(new WaitCallback(Netplay.ListenForClients), 1);
             }
         }
         int num4 = 0;
         for (int k = 0; k < 9; k++)
         {
             if (NetMessage.buffer[k].checkBytes)
             {
                 NetMessage.CheckBytes(k);
             }
             if (serverSock[k].kill)
             {
                 serverSock[k].Reset();
                 NetMessage.syncPlayers();
             }
             else if (serverSock[k].tcpClient.Connected)
             {
                 if (!serverSock[k].active)
                 {
                     serverSock[k].state = 0;
                 }
                 serverSock[k].active = true;
                 num4++;
                 if (!serverSock[k].locked)
                 {
                     try
                     {
                         serverSock[k].networkStream = serverSock[k].tcpClient.GetStream();
                         if (serverSock[k].networkStream.DataAvailable)
                         {
                             serverSock[k].locked = true;
                             serverSock[k].networkStream.BeginRead(serverSock[k].readBuffer, 0, serverSock[k].readBuffer.Length, new AsyncCallback(serverSock[k].ServerReadCallBack), serverSock[k].networkStream);
                         }
                     }
                     catch
                     {
                         serverSock[k].kill = true;
                     }
                 }
                 if ((serverSock[k].statusMax > 0) && (serverSock[k].statusText2 != ""))
                 {
                     if (serverSock[k].statusCount >= serverSock[k].statusMax)
                     {
                         serverSock[k].statusText  = string.Concat(new object[] { "(", serverSock[k].tcpClient.Client.RemoteEndPoint, ") ", serverSock[k].name, " ", serverSock[k].statusText2, ": Complete!" });
                         serverSock[k].statusText2 = "";
                         serverSock[k].statusMax   = 0;
                         serverSock[k].statusCount = 0;
                     }
                     else
                     {
                         serverSock[k].statusText = string.Concat(new object[] { "(", serverSock[k].tcpClient.Client.RemoteEndPoint, ") ", serverSock[k].name, " ", serverSock[k].statusText2, ": ", (int)((((float)serverSock[k].statusCount) / ((float)serverSock[k].statusMax)) * 100f), "%" });
                     }
                 }
                 else if (serverSock[k].state == 0)
                 {
                     serverSock[k].statusText = string.Concat(new object[] { "(", serverSock[k].tcpClient.Client.RemoteEndPoint, ") ", serverSock[k].name, " is connecting..." });
                 }
                 else if (serverSock[k].state == 1)
                 {
                     serverSock[k].statusText = string.Concat(new object[] { "(", serverSock[k].tcpClient.Client.RemoteEndPoint, ") ", serverSock[k].name, " is sending player data..." });
                 }
                 else if (serverSock[k].state == 2)
                 {
                     serverSock[k].statusText = string.Concat(new object[] { "(", serverSock[k].tcpClient.Client.RemoteEndPoint, ") ", serverSock[k].name, " requested world information" });
                 }
                 else if ((serverSock[k].state != 3) && (serverSock[k].state == 10))
                 {
                     serverSock[k].statusText = string.Concat(new object[] { "(", serverSock[k].tcpClient.Client.RemoteEndPoint, ") ", serverSock[k].name, " is playing" });
                 }
             }
             else if (serverSock[k].active)
             {
                 serverSock[k].kill = true;
             }
             else
             {
                 serverSock[k].statusText2 = "";
                 if (k < 8)
                 {
                     Main.player[k].active = false;
                 }
             }
             Thread.Sleep(1);
         }
         if (!WorldGen.saveLock)
         {
             if (num4 == 0)
             {
                 Main.statusText = "Waiting for clients...";
             }
             else
             {
                 Main.statusText = num4 + " clients connected";
             }
         }
     }
     tcpListener.Stop();
     for (int j = 0; j < 9; j++)
     {
         serverSock[j].Reset();
     }
     if (Main.menuMode != 15)
     {
         Main.netMode  = 0;
         Main.menuMode = 10;
         WorldGen.saveWorld(false);
         while (WorldGen.saveLock)
         {
         }
         Main.menuMode = 0;
     }
     else
     {
         Main.netMode = 0;
     }
     Main.myPlayer = 0;
 }
 public static void SendBytes(ServerSock sock, byte[] buffer, int offset, int count, AsyncCallback callback, object state)
 {
     try
     {
         if (ServerApi.Hooks.InvokeNetSendBytes(sock, buffer, offset, count))
         {
             return;
         }
         if (Main.runningMono)
             sock.networkStream.Write(buffer, offset, count);
         else
             sock.networkStream.BeginWrite(buffer, offset, count, callback, state);
     }
     catch (Exception e)
     {
         Console.WriteLine("{0} had an exception thrown when trying to send data.", sock.tcpClient.Client.RemoteEndPoint);
         Console.WriteLine(e);
         sock.kill = true;
     }
 }
 void SendBytes(ServerSock socket, byte[] buffer, int offset, int count, HandledEventArgs e)
 {
     try
     {
         if (esPlayers[socket.whoAmI].ptTime < 0.0) return;
         switch (buffer[4])
         {
             case 7:
                 Buffer.BlockCopy(BitConverter.GetBytes((int)esPlayers[socket.whoAmI].ptTime), 0, buffer, 5, 4);
                 buffer[9] = (byte)(esPlayers[socket.whoAmI].ptDay ? 1 : 0);
                 break;
             case 18:
                 buffer[5] = (byte)(esPlayers[socket.whoAmI].ptDay ? 1 : 0);
                 Buffer.BlockCopy(BitConverter.GetBytes((int)esPlayers[socket.whoAmI].ptTime), 0, buffer, 6, 4);
                 break;
         }
     }
     catch { }
 }
Beispiel #8
0
 /// <summary>
 /// Send bytes to a client ignoring the packet buffer
 /// </summary>
 /// <param name="client">socket to send to</param>
 /// <param name="bytes">bytes to send</param>
 /// <returns>False on exception</returns>
 public static bool SendBytesBufferless(ServerSock client, byte[] bytes)
 {
     try
     {
         if (client.tcpClient.Connected)
             client.networkStream.Write(bytes, 0, bytes.Length);
         return true;
     }
     catch (Exception ex)
     {
         Log.Warn("This is a normal exception");
         Log.Warn(ex.ToString());
     }
     return false;
 }
Beispiel #9
0
        public static bool OnSendBytes(ServerSock socket, byte[] buffer, int offset, int count)
        {
            if (SendBytes == null)
                return false;

            var args = new HandledEventArgs();
            SendBytes(socket, buffer, offset, count, args);
            return args.Handled;
        }
Beispiel #10
0
        public static void ServerLoop(object threadContext)
        {
            if (Main.rand == null)
            {
                Main.rand = new Random((int) DateTime.Now.Ticks);
            }
            if (WorldGen.genRand == null)
            {
                WorldGen.genRand = new Random((int) DateTime.Now.Ticks);
            }
            Main.myPlayer = 0xff;
            serverIP = IPAddress.Any;
            serverListenIP = serverIP;
            Main.menuMode = 14;
            Main.statusText = "Starting server...";
            Main.netMode = 2;
            disconnect = false;
            int index = 0;
            while (index < 0x100)
            {
                serverSock[index] = new ServerSock();
                serverSock[index].Reset();
                serverSock[index].whoAmI = index;
                serverSock[index].tcpClient = new TcpClient();
                serverSock[index].tcpClient.NoDelay = false;
                serverSock[index].readBuffer = new byte[0x400];
                serverSock[index].writeBuffer = new byte[0x400];
                index++;
            }
            tcpListener = new TcpListener(serverListenIP, serverPort);
            try
            {
                tcpListener.Start();
            }
            catch (Exception exception)
            {
                Main.menuMode = 15;
                Main.statusText = exception.ToString();
                disconnect = true;
                Debug.WriteLine("   Exception normal: Tried to run two servers on the same PC");
            }
            if (!disconnect)
            {
                ThreadPool.QueueUserWorkItem(new WaitCallback(Netplay.ListenForClients), 1);
                Main.statusText = "Server started";
            }
            int num2 = 0;
            while (!disconnect)
            {
                if (stopListen)
                {
                    int num3 = -1;
                    index = 0;
                    while (index < 0xff)
                    {
                        if (!serverSock[index].tcpClient.Connected)
                        {
                            num3 = index;
                            break;
                        }
                        index++;
                    }
                    if (num3 >= 0)
                    {
                        tcpListener.Start();
                        stopListen = false;
                        ThreadPool.QueueUserWorkItem(new WaitCallback(Netplay.ListenForClients), 1);
                    }
                }
                int num4 = 0;
                index = 0;
                while (index < 0x100)
                {
                    try
                    {
                        if (NetMessage.buffer[index].checkBytes)
                        {
                            NetMessage.CheckBytes(index);
                        }
                        if (serverSock[index].kill)
                        {
                            serverSock[index].Reset();
                            NetMessage.syncPlayers();
                        }
                        else if (serverSock[index].tcpClient.Connected)
                        {
                            if (!serverSock[index].active)
                            {
                                serverSock[index].state = 0;
                            }
                            serverSock[index].active = true;
                            num4++;
                            if (!serverSock[index].locked)
                            {
                                try
                                {
                                    serverSock[index].networkStream = serverSock[index].tcpClient.GetStream();
                                    if (serverSock[index].networkStream.DataAvailable)
                                    {
                                        serverSock[index].locked = true;
                                        serverSock[index].networkStream.BeginRead(serverSock[index].readBuffer, 0, serverSock[index].readBuffer.Length, new AsyncCallback(serverSock[index].ServerReadCallBack), serverSock[index].networkStream);
                                    }
                                }
                                catch
                                {
                                    Debug.WriteLine("   Exception normal: Tried to get data from a client after losing connection");
                                    serverSock[index].kill = true;
                                }
                            }
                            if ((serverSock[index].statusMax > 0) && (serverSock[index].statusText2 != ""))
                            {
                                if (serverSock[index].statusCount >= serverSock[index].statusMax && serverSock[index].tcpClient.Client.Connected)
                                {

                                    string status = string.Concat(new object[] { "(", serverSock[index].tcpClient.Client.RemoteEndPoint, ") ", serverSock[index].name, " ", serverSock[index].statusText2, ": Complete!" });
                                    // Trace.WriteLine("Test1: {0}", status); //TODO: Remove the RemoteEndPoint
                                    serverSock[index].statusText = status;
                                    serverSock[index].statusText2 = "";
                                    serverSock[index].statusMax = 0;
                                    serverSock[index].statusCount = 0;
                                }
                                else
                                {
                                    var sock = serverSock[index];
                                    string status = string.Concat(new object[] { "(", sock.tcpClient.Client.RemoteEndPoint, ") ", sock.name, " ", sock.statusText2, ": ", (int)((((float)sock.statusCount) / ((float)sock.statusMax)) * 100f), "%" });
                                    //  Trace.WriteLine("Test2: {0}", status); //TODO: Remove the RemoteEndPoint
                                    sock.statusText = status;
                                }
                            }
                            else if (serverSock[index].state == 0)
                            {
                                string status = string.Concat(new object[] { "(", serverSock[index].tcpClient.Client.RemoteEndPoint, ") ", serverSock[index].name, " is connecting..." });
                                //Trace.WriteLine("Test3: {0}", status); //TODO: Remove the RemoteEndPoint
                                serverSock[index].statusText = status;
                            }
                            else if (serverSock[index].state == 1)
                            {
                                string status = string.Concat(new object[] { "(", serverSock[index].tcpClient.Client.RemoteEndPoint, ") ", serverSock[index].name, " is sending player data..." });
                                //Trace.WriteLine("Test4: {0}", status); //TODO: Remove the RemoteEndPoint
                                serverSock[index].statusText = status;
                            }
                            else if (serverSock[index].state == 2)
                            {
                                string status = string.Concat(new object[] { "(", serverSock[index].tcpClient.Client.RemoteEndPoint, ") ", serverSock[index].name, " requested world information" });
                                //Trace.WriteLine("Test5: {0}", status); //TODO: Remove the RemoteEndPoint
                                serverSock[index].statusText = status;
                            }
                            else if ((serverSock[index].state != 3) && (serverSock[index].state == 10))
                            {

                                string status = string.Concat(new object[] { "(", serverSock[index].tcpClient.Client.RemoteEndPoint, ") ", serverSock[index].name, " is playing" });
                                // Trace.WriteLine("Test6: {0}", status); //TODO: Remove the RemoteEndPoint
                                serverSock[index].statusText = status;
                            }
                        }
                        else if (serverSock[index].active)
                        {
                            serverSock[index].kill = true;
                        }
                        else
                        {
                            serverSock[index].statusText2 = "";
                            if (index < 0xff)
                            {
                                Main.player[index].active = false;
                            }
                        }

                    }
                    catch (Exception ex)
                    {

                        Trace.WriteLine(String.Format("Exception Caught: Message {0} :: StackTrace {1}", ex.Message, ex.StackTrace));
                    }
                    index++;
                }
                num2++;
                if (num2 > 10)
                {
                    Thread.Sleep(1);
                    num2 = 0;
                }
                else
                {
                    Thread.Sleep(0);
                }
                if (!WorldGen.saveLock && !Main.dedServ)
                {
                    if (num4 == 0)
                    {
                        Main.statusText = "Waiting for clients...";
                    }
                    else
                    {
                        Main.statusText = num4 + " clients connected";
                    }
                }
                ServerUp = true;
            }
            tcpListener.Stop();
            for (index = 0; index < 0x100; index++)
            {
                serverSock[index].Reset();
            }
            if (Main.menuMode != 15)
            {
                Main.netMode = 0;
                Main.menuMode = 10;
                WorldGen.saveWorld(false);
                while (WorldGen.saveLock)
                {
                }
                Main.menuMode = 0;
            }
            else
            {
                Main.netMode = 0;
            }
            Main.myPlayer = 0;
        }
Beispiel #11
0
		internal void InvokeServerSocketReset(ServerSock socket)
		{
			SocketResetEventArgs args = new SocketResetEventArgs
			{
				Socket = socket
			};

			this.ServerSocketReset.Invoke(args);
		}
Beispiel #12
0
		internal bool InvokeNetSendBytes(ServerSock socket, byte[] buffer, int offset, int count)
		{
			SendBytesEventArgs args = new SendBytesEventArgs
			{
				Socket = socket,
				Buffer = buffer,
				Offset = offset,
				Count = count
			};

			this.NetSendBytes.Invoke(args);
			return args.Handled;
		}
Beispiel #13
0
 void OnSendBytes(ServerSock sock, byte[] buffer, int offset, int count, HandledEventArgs e)
 {
     bool build = Build[sock.whoAmI];
     switch (buffer[4])
     {
         case 7:
             Buffer.BlockCopy(BitConverter.GetBytes(build ? 27000 : (int)Main.time), 0, buffer, 5, 4);
             buffer[9] = (byte)(Main.dayTime || build ? 1 : 0);
             Buffer.BlockCopy(BitConverter.GetBytes(build ? Main.maxTilesY : (int)Main.worldSurface), 0, buffer, 28, 4);
             Buffer.BlockCopy(BitConverter.GetBytes(build ? Main.maxTilesY : (int)Main.rockLayer), 0, buffer, 32, 4);
             break;
         case 18:
             buffer[5] = (byte)(Main.dayTime || build ? 1 : 0);
             Buffer.BlockCopy(BitConverter.GetBytes(build ? 27000 : (int)Main.time), 0, buffer, 6, 4);
             break;
         case 23:
             NPC npc = Main.npc[BitConverter.ToInt16(buffer, 5)];
             if (!npc.friendly)
             {
                 Buffer.BlockCopy(BitConverter.GetBytes(build ? 0 : npc.life), 0, buffer, 27, 4);
             }
             break;
         case 27:
             short id = BitConverter.ToInt16(buffer, 5);
             int owner = buffer[29];
             Projectile proj = Main.projectile[TShock.Utils.SearchProjectile(id, owner)];
             if (!proj.friendly)
             {
                 buffer[30] = (byte)(build ? 0 : proj.type);
             }
             break;
     }
 }
 public static void SendBytes(ServerSock sock, byte[] buffer, int offset, int count, AsyncCallback callback, object state)
 {
     if (NetHooks.OnSendBytes(sock, buffer, offset, count))
     {
         return;
     }
     sock.networkStream.BeginWrite(buffer, offset, count, callback, state);
 }
Beispiel #15
0
 public static void Init()
 {
     for (int i = 0; i < 0x101; i++)
     {
         if (i < 0x100)
         {
             serverSock[i] = new ServerSock();
             serverSock[i].tcpClient.NoDelay = true;
         }
         NetMessage.buffer[i] = new messageBuffer();
         NetMessage.buffer[i].whoAmI = i;
     }
     clientSock.tcpClient.NoDelay = true;
 }
Beispiel #16
0
        /// <summary>
        /// Send bytes to client using packetbuffering if available
        /// </summary>
        /// <param name="client">socket to send to</param>
        /// <param name="bytes">bytes to send</param>
        /// <returns>False on exception</returns>
        public static bool SendBytes(ServerSock client, byte[] bytes)
        {
            if (PacketBuffer != null)
            {
                PacketBuffer.BufferBytes(client, bytes);
                return true;
            }

            return SendBytesBufferless(client, bytes);
        }
Beispiel #17
0
 public static void ServerLoop(object threadContext)
 {
     ResetNetDiag();
     if (Main.rand == null)
     {
         Main.rand = new Random((int) DateTime.Now.Ticks);
     }
     if (WorldGen.genRand == null)
     {
         WorldGen.genRand = new Random((int) DateTime.Now.Ticks);
     }
     Main.myPlayer = 0xff;
     serverIP = IPAddress.Any;
     serverListenIP = serverIP;
     Main.menuMode = 14;
     Main.statusText = "Starting server...";
     Main.netMode = 2;
     disconnect = false;
     for (int i = 0; i < 0x100; i++)
     {
         serverSock[i] = new ServerSock();
         serverSock[i].Reset();
         serverSock[i].whoAmI = i;
         serverSock[i].tcpClient = new TcpClient();
         serverSock[i].tcpClient.NoDelay = true;
         serverSock[i].readBuffer = new byte[0x400];
         serverSock[i].writeBuffer = new byte[0x400];
     }
     tcpListener = new TcpListener(serverListenIP, serverPort);
     try
     {
         tcpListener.Start();
     }
     catch (Exception exception)
     {
         Main.menuMode = 15;
         Main.statusText = exception.ToString();
         disconnect = true;
     }
     if (!disconnect)
     {
         ThreadPool.QueueUserWorkItem(new WaitCallback(Netplay.ListenForClients), 1);
         Main.statusText = "Server started";
     }
     int num2 = 0;
     while (!disconnect)
     {
         if (stopListen)
         {
             int num3 = -1;
             for (int m = 0; m < Main.maxNetPlayers; m++)
             {
                 if (!serverSock[m].tcpClient.Connected)
                 {
                     num3 = m;
                     break;
                 }
             }
             if (num3 >= 0)
             {
                 if (Main.ignoreErrors)
                 {
                     try
                     {
                         tcpListener.Start();
                         stopListen = false;
                         ThreadPool.QueueUserWorkItem(new WaitCallback(Netplay.ListenForClients), 1);
                     }
                     catch
                     {
                     }
                 }
                 else
                 {
                     tcpListener.Start();
                     stopListen = false;
                     ThreadPool.QueueUserWorkItem(new WaitCallback(Netplay.ListenForClients), 1);
                 }
             }
         }
         int num5 = 0;
         for (int k = 0; k < 0x100; k++)
         {
             if (NetMessage.buffer[k].checkBytes)
             {
                 NetMessage.CheckBytes(k);
             }
             if (serverSock[k].kill)
             {
                 serverSock[k].Reset();
                 NetMessage.syncPlayers();
             }
             else if (serverSock[k].tcpClient.Connected)
             {
                 if (!serverSock[k].active)
                 {
                     serverSock[k].state = 0;
                 }
                 serverSock[k].active = true;
                 num5++;
                 if (!serverSock[k].locked)
                 {
                     try
                     {
                         serverSock[k].networkStream = serverSock[k].tcpClient.GetStream();
                         if (serverSock[k].networkStream.DataAvailable)
                         {
                             serverSock[k].locked = true;
                             serverSock[k].networkStream.BeginRead(serverSock[k].readBuffer, 0, serverSock[k].readBuffer.Length, new AsyncCallback(serverSock[k].ServerReadCallBack), serverSock[k].networkStream);
                         }
                     }
                     catch
                     {
                         serverSock[k].kill = true;
                     }
                 }
                 if ((serverSock[k].statusMax > 0) && (serverSock[k].statusText2 != ""))
                 {
                     if (serverSock[k].statusCount >= serverSock[k].statusMax)
                     {
                         serverSock[k].statusText = string.Concat(new object[] { "(", serverSock[k].tcpClient.Client.RemoteEndPoint, ") ", serverSock[k].name, " ", serverSock[k].statusText2, ": Complete!" });
                         serverSock[k].statusText2 = "";
                         serverSock[k].statusMax = 0;
                         serverSock[k].statusCount = 0;
                     }
                     else
                     {
                         serverSock[k].statusText = string.Concat(new object[] { "(", serverSock[k].tcpClient.Client.RemoteEndPoint, ") ", serverSock[k].name, " ", serverSock[k].statusText2, ": ", (int) ((((float) serverSock[k].statusCount) / ((float) serverSock[k].statusMax)) * 100f), "%" });
                     }
                 }
                 else if (serverSock[k].state == 0)
                 {
                     serverSock[k].statusText = string.Concat(new object[] { "(", serverSock[k].tcpClient.Client.RemoteEndPoint, ") ", serverSock[k].name, " is connecting..." });
                 }
                 else if (serverSock[k].state == 1)
                 {
                     serverSock[k].statusText = string.Concat(new object[] { "(", serverSock[k].tcpClient.Client.RemoteEndPoint, ") ", serverSock[k].name, " is sending player data..." });
                 }
                 else if (serverSock[k].state == 2)
                 {
                     serverSock[k].statusText = string.Concat(new object[] { "(", serverSock[k].tcpClient.Client.RemoteEndPoint, ") ", serverSock[k].name, " requested world information" });
                 }
                 else if ((serverSock[k].state != 3) && (serverSock[k].state == 10))
                 {
                     serverSock[k].statusText = string.Concat(new object[] { "(", serverSock[k].tcpClient.Client.RemoteEndPoint, ") ", serverSock[k].name, " is playing" });
                 }
             }
             else if (serverSock[k].active)
             {
                 serverSock[k].kill = true;
             }
             else
             {
                 serverSock[k].statusText2 = "";
                 if (k < 0xff)
                 {
                     Main.player[k].active = false;
                 }
             }
         }
         num2++;
         if (num2 > 10)
         {
             Thread.Sleep(1);
             num2 = 0;
         }
         else
         {
             Thread.Sleep(0);
         }
         if (!WorldGen.saveLock && !Main.dedServ)
         {
             if (num5 == 0)
             {
                 Main.statusText = "Waiting for clients...";
             }
             else
             {
                 Main.statusText = num5 + " clients connected";
             }
         }
         if (num5 == 0)
         {
             anyClients = false;
         }
         else
         {
             anyClients = true;
         }
         ServerUp = true;
     }
     tcpListener.Stop();
     for (int j = 0; j < 0x100; j++)
     {
         serverSock[j].Reset();
     }
     if (Main.menuMode != 15)
     {
         Main.netMode = 0;
         Main.menuMode = 10;
         WorldGen.saveWorld(false);
         while (WorldGen.saveLock)
         {
         }
         Main.menuMode = 0;
     }
     else
     {
         Main.netMode = 0;
     }
     Main.myPlayer = 0;
 }
Beispiel #18
0
 public static void OnSocketReset(ServerSock socket)
 {
     if (SocketReset != null)
         SocketReset(socket);
 }