Пример #1
0
 public void DirectConnection()
 {
     Netplay.ListenPort = _port;
     Netplay.SetRemoteIP("127.0.0.1");
     Netplay.Connection.Socket.Close();
     Netplay.StartTcpClient();
 }
Пример #2
0
        public static void LoadWorld(On.Terraria.IO.WorldFile.orig_loadWorld orig, bool loadFromCloud)
        {
            int startingPort;

            ChatServer.instance.Load();
            if (Main.netMode == 0)
            {
                startingPort = 7777;
                StartServer(ref startingPort, false);
                Main.netMode = 1;
                Netplay.SetRemoteIP("127.0.0.1");
                Netplay.ListenPort = 7777;
                Netplay.Connection.Socket.Close();
                Netplay.StartTcpClient();
            }
            else if (Main.netMode == 2)
            {
                orig.Invoke(loadFromCloud);
                if (Netplay.ListenPort == 7777 && Program.LaunchParameters.ContainsKey("FromHost"))
                {
                    startingPort = 7778;
                    StartServer(ref startingPort, true);
                }

                if (Program.LaunchParameters.ContainsKey("-port"))
                {
                    Netplay.ListenPort = Int32.Parse(Program.LaunchParameters["-port"]);
                }
                Dimlibs.Instance.Logger.Info(Netplay.ListenPort);
                Dimlibs.dimensionInstanceHandlers[Dimlibs.dimension].handler.Load();
            }
        }
Пример #3
0
 /// <summary>
 /// Connects the current machine to a server to begin a game. Meant to be called from the main menu.
 /// </summary>
 /// <param name="ip"></param>
 /// <param name="port"></param>
 public static void JoinServer(string ip, int port)
 {
     Main.autoPass      = false;
     Netplay.ListenPort = port;
     Main.getIP         = ip;
     Main.defaultIP     = ip;
     if (Netplay.SetRemoteIP(ip))
     {
         Main.menuMode = 10;
         Netplay.StartTcpClient();
     }
 }
Пример #4
0
 private void SaveAndConnectClick(UIMouseEvent evt, UIElement listeningElement)
 {
     SaveServer();
     Main.autoPass      = false;
     Netplay.ListenPort = BetterServerList.ActiveServer.Port;
     Main.getIP         = BetterServerList.ActiveServer.Address;
     if (Netplay.SetRemoteIP(Main.getIP))
     {
         Main.menuMode = 10;
         Netplay.StartTcpClient();
     }
 }
Пример #5
0
        public void ClientThread(object context)
        {
            Main.gameMenu = true;
            Main.menuMode = 888;
            Main.MenuUI.SetState(new UINetworkConnection());
            object[]  parameter       = (object[])context;
            bool      exitThread      = false;
            DimPlayer player          = (DimPlayer)parameter[0];
            int       numberOfAttempt = 0;

            RemoteAddress adress = new TcpAddress(Netplay.ServerIP, 7776);

            ClientLoopSetup(adress);
            ISocket secondarySocket = new TcpSocket();

            secondarySocket.Connect(new TcpAddress(Netplay.ServerIP, 7776));

            while (!exitThread)
            {
                try
                {
                    Thread.Sleep(2500);
                    if (secondarySocket.IsDataAvailable())
                    {
                        byte[] data = new byte[ushort.MaxValue];
                        secondarySocket.AsyncReceive(data, 0, ushort.MaxValue, new SocketReceiveCallback(Netplay.Connection.ClientReadCallBack), null);
                        using (MemoryStream stream = new MemoryStream(data))
                        {
                            BinaryReader reader = new BinaryReader(new MemoryStream(data));
                        }
                        numberOfAttempt++;
                    }
                    else
                    {
                        byte[] data = new byte[ushort.MaxValue];
                        using (MemoryStream stream = new MemoryStream(data))
                        {
                            BinaryWriter writer = new BinaryWriter(stream);
                            writer.Write("hey");
                            secondarySocket.AsyncSend(writer.BaseStream.ReadAllBytes(), 0, ushort.MaxValue, new SocketSendCallback(Netplay.Connection.ClientWriteCallBack), null);
                        }
                    }
                }
                catch (Exception e)
                {
                    LogManager.GetLogger("Second thread").Error(e.Message, e);
                }
            }
            Netplay.Connection.Socket.Close();
            Netplay.StartTcpClient();
            player.inTransit = false;
        }
Пример #6
0
 public void DistantConnection()
 {
     Netplay.ListenPort = _port;
     Netplay.Connection.Socket.Close();
     Netplay.StartTcpClient();
 }