Example #1
0
 public static void SyncPortalsOnPlayerJoin(int plr, int fluff, List <Point> dontInclude, out List <Point> portals, out List <Point> portalCenters)
 {
     portals       = new List <Point>();
     portalCenters = new List <Point>();
     for (int index = 0; index < 1000; ++index)
     {
         Projectile projectile = Main.projectile[index];
         if (projectile.active && (projectile.type == 602 || projectile.type == 601))
         {
             Vector2 center   = projectile.Center;
             int     sectionX = Netplay.GetSectionX((int)((double)center.X / 16.0));
             int     sectionY = Netplay.GetSectionY((int)((double)center.Y / 16.0));
             for (int x = sectionX - fluff; x < sectionX + fluff + 1; ++x)
             {
                 for (int y = sectionY - fluff; y < sectionY + fluff + 1; ++y)
                 {
                     if (x >= 0 && x < Main.maxSectionsX && (y >= 0 && y < Main.maxSectionsY) && (!Netplay.Clients[plr].TileSections[x, y] && !dontInclude.Contains(new Point(x, y))))
                     {
                         portals.Add(new Point(x, y));
                         if (!portalCenters.Contains(new Point(sectionX, sectionY)))
                         {
                             portalCenters.Add(new Point(sectionX, sectionY));
                         }
                     }
                 }
             }
         }
     }
 }
Example #2
0
        public static void OpenPort()
        {
#if ENABLE_NAT
            Netplay.portForwardIP   = Netplay.LocalIPAddress();
            Netplay.portForwardPort = Netplay.serverPort;

            Mono.Nat.NatUtility.DeviceFound += NatUtility_DeviceFound;
            Mono.Nat.NatUtility.StartDiscovery();
#endif

            //if (Netplay.mappings != null)
            //{
            //    foreach (IStaticPortMapping staticPortMapping in Netplay.mappings)
            //    {
            //        if (staticPortMapping.InternalPort == Netplay.portForwardPort && staticPortMapping.InternalClient == Netplay.portForwardIP && staticPortMapping.Protocol == "TCP")
            //        {
            //            Netplay.portForwardOpen = true;
            //        }
            //    }
            //    if (!Netplay.portForwardOpen)
            //    {
            //        Netplay.mappings.Add(Netplay.portForwardPort, "TCP", Netplay.portForwardPort, Netplay.portForwardIP, true, "Terraria Server");
            //        Netplay.portForwardOpen = true;
            //    }
            //}
        }
 public static void SendSection(int whoAmi, int sectionX, int sectionY, bool skipSent = false)
 {
     if (sectionX >= 0 && sectionY >= 0 && sectionX < Main.maxSectionsX && sectionY < Main.maxSectionsY)
     {
         if (!skipSent || !Terraria.Netplay.Clients[whoAmi].TileSections[sectionX, sectionY])
         {
             Terraria.Netplay.Clients[whoAmi].TileSections[sectionX, sectionY] = true;
             int number = sectionX * 200;
             int num    = sectionY * 150;
             int num2   = 150;
             for (int i = num; i < num + 150; i += num2)
             {
                 NewNetMessage.SendData(10, whoAmi, -1, "", number, (float)i, 200f, (float)num2, 0);
             }
             for (int j = 0; j < 200; j++)
             {
                 if (Main.npc[j].active && Main.npc[j].townNPC)
                 {
                     int sectionX2 = Netplay.GetSectionX((int)(Main.npc[j].position.X / 16f));
                     int sectionY2 = Netplay.GetSectionY((int)(Main.npc[j].position.Y / 16f));
                     if (sectionX2 == sectionX && sectionY2 == sectionY)
                     {
                         NewNetMessage.SendData(23, whoAmi, -1, "", j, 0f, 0f, 0f, 0);
                     }
                 }
             }
         }
     }
 }
Example #4
0
        // World replacement
        public static void ReplaceTiles(int i, int j, Hooks.TileData data, int style = 0)
        {
            WorldGen.PlaceTile(i, j, data.type, true, true, -1, style);
            if (data.wall != 0)
            {
                WorldGen.PlaceWall(i, j, data.wall, true);
            }

            OTAPI.Tile.ITile tile = Main.tile[i, j];
            tile.type = data.type;
            if (data.halfBrick)
            {
                tile.halfBrick(data.halfBrick);
            }
            else
            {
                tile.slope(data.slope);
            }
            //  TODO: sort out slopes after replacing the tiles. This is returning a System.IndexOutOfRangeException.
            int x = Netplay.GetSectionX(i);
            int y = Netplay.GetSectionY(j);

            foreach (RemoteClient sock in Netplay.Clients.Where(t => t.IsActive))
            {
                sock.TileSections[x, y] = false;
            }
        }
        /// <summary>
        /// Requests all tile chunks (200x150 tile 'sections') from the server within a given tile range.
        /// </summary>
        /// <param name="tileRange"></param>
        /// <param name="leftPadding">In chunks.</param>
        /// <param name="topPadding">In chunks.</param>
        /// <param name="rightPadding">In chunks.</param>
        /// <param name="bottomPadding">In chunks.</param>
        public static void RequestChunksFromServer(
            Rectangle tileRange,
            int leftPadding   = 0,
            int topPadding    = 0,
            int rightPadding  = 0,
            int bottomPadding = 0)
        {
            int sectX = 200;
            int sectY = 150;

            int minX = Math.Max((tileRange.X / sectX) - leftPadding, 0);

            minX *= sectX;
            int minY = Math.Max((tileRange.Y / sectY) - topPadding, 0);

            minY *= sectY;

            int maxX = tileRange.X + tileRange.Width;

            maxX += rightPadding * sectX;
            maxX  = Math.Min(maxX, Main.maxTilesX - 1);
            int maxY = tileRange.Y + tileRange.Height;

            maxY += bottomPadding * sectY;
            maxY  = Math.Min(maxY, Main.maxTilesY - 1);

            for (int x = minX; x < maxX; x += sectX)
            {
                for (int y = minY; y < maxY; y += sectY)
                {
                    TileWorldLibraries.RequestChunkFromServer(Netplay.GetSectionX(x), Netplay.GetSectionY(y));
                }
            }
        }
Example #6
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();
            }
        }
Example #7
0
 public static void SyncPortalsOnPlayerJoin(int plr, int fluff, List <Point> dontInclude, out List <Point> portals, out List <Point> portalCenters)
 {
     portals       = new List <Point>();
     portalCenters = new List <Point>();
     for (int index1 = 0; index1 < 1000; ++index1)
     {
         Projectile projectile = Main.projectile[index1];
         if (projectile.active && (projectile.type == 602 || projectile.type == 601))
         {
             Vector2 center   = projectile.Center;
             int     sectionX = Netplay.GetSectionX((int)(center.X / 16.0));
             int     sectionY = Netplay.GetSectionY((int)(center.Y / 16.0));
             for (int index2 = sectionX - fluff; index2 < sectionX + fluff + 1; ++index2)
             {
                 for (int index3 = sectionY - fluff; index3 < sectionY + fluff + 1; ++index3)
                 {
                     if (index2 >= 0 && index2 < Main.maxSectionsX && (index3 >= 0 && index3 < Main.maxSectionsY) && (!Netplay.Clients[plr].TileSections[index2, index3] && !dontInclude.Contains(new Point(index2, index3))))
                     {
                         portals.Add(new Point(index2, index3));
                         if (!portalCenters.Contains(new Point(sectionX, sectionY)))
                         {
                             portalCenters.Add(new Point(sectionX, sectionY));
                         }
                     }
                 }
             }
         }
     }
 }
Example #8
0
 public static void SyncPortalsOnPlayerJoin(int plr, int fluff, List <Point> dontInclude, out List <Point> portals, out List <Point> portalCenters)
 {
     portals       = new List <Point>();
     portalCenters = new List <Point>();
     for (int i = 0; i < 1000; i++)
     {
         Projectile projectile = Main.projectile[i];
         if (!projectile.active || (projectile.type != 602 && projectile.type != 601))
         {
             continue;
         }
         Vector2 center   = projectile.Center;
         int     sectionX = Netplay.GetSectionX((int)(center.X / 16f));
         int     sectionY = Netplay.GetSectionY((int)(center.Y / 16f));
         for (int j = sectionX - fluff; j < sectionX + fluff + 1; j++)
         {
             for (int k = sectionY - fluff; k < sectionY + fluff + 1; k++)
             {
                 if (j >= 0 && j < Main.maxSectionsX && k >= 0 && k < Main.maxSectionsY && !Netplay.Clients[plr].TileSections[j, k] && !dontInclude.Contains(new Point(j, k)))
                 {
                     portals.Add(new Point(j, k));
                     if (!portalCenters.Contains(new Point(sectionX, sectionY)))
                     {
                         portalCenters.Add(new Point(sectionX, sectionY));
                     }
                 }
             }
         }
     }
 }
Example #9
0
        public static void ResendPlayerTileData(HEROsModPlayer player)
        {
            int sectionX = Netplay.GetSectionX((int)(player.GameInstance.position.X / 16f));
            int sectionY = Netplay.GetSectionY((int)(player.GameInstance.position.Y / 16f));

            int num = 0;

            for (int i = sectionX - 1; i < sectionX + 2; i++)
            {
                for (int j = sectionY - 1; j < sectionY + 2; j++)
                {
                    if (i >= 0 && i < Main.maxSectionsX && j >= 0 && j < Main.maxSectionsY)
                    {
                        num++;
                    }
                }
            }
            int num2 = num;

            NetMessage.SendData(9, player.Index, -1, Lang.inter[44].ToNetworkText(), num2, 0f, 0f, 0f, 0);
            Netplay.Clients[player.Index].StatusText2 = "is receiving tile data";
            Netplay.Clients[player.Index].StatusMax  += num2;
            for (int k = sectionX - 1; k < sectionX + 2; k++)
            {
                for (int l = sectionY - 1; l < sectionY + 2; l++)
                {
                    if (k >= 0 && k < Main.maxSectionsX && l >= 0 && l < Main.maxSectionsY)
                    {
                        NetMessage.SendSection(player.Index, k, l, false);
                        NetMessage.SendData(11, player.Index, -1, null, k, (float)l, (float)k, (float)l, 0);
                    }
                }
            }
        }
Example #10
0
        void BRTimer(object obj)
        {
            Region region = TShock.Regions.GetRegionByName("BR");

            if (MyTiles.Count > 0 && region != null)
            {
                for (byte i = 0; i < MyTiles.Count; i++)
                {
                    Main.tile[MyTiles[i].X, MyTiles[i].Y].ResetToType(MyTiles[i].Type);
                }
                MyTiles.Clear();
                TSPlayer.All.SendData(PacketTypes.TileSendSection, null, region.Area.X, region.Area.Y, region.Area.Width, region.Area.Height);
                TSPlayer.All.SendData(PacketTypes.TileFrameSection, null, Netplay.GetSectionX(region.Area.X), Netplay.GetSectionY(region.Area.Y), Netplay.GetSectionX(region.Area.X + region.Area.Width), Netplay.GetSectionY(region.Area.Y + region.Area.Height));
                if (config.ping)
                {
                    Color color = new Color(173, 137, 69);
                    foreach (TSPlayer plr in TShock.Players.Where(p => p != null && p.ConnectionAlive && p.RealPlayer && p.HasPermission("br.ping")))
                    {
                        NetMessage.SendData(58, plr.Index, -1, null, plr.Index, -0.2410251f);
                        plr.SendData(PacketTypes.CreateCombatTextExtended, "Blocks Regenerated!", (int)color.PackedValue, plr.X, plr.Y);
                        Thread.Sleep(500);
                        NetMessage.SendData(58, plr.Index, -1, null, plr.Index, -0.6057936f);
                    }
                }
            }
        }
        public new bool SectionRange(int size, int firstX, int firstY)
        {
            for (var i = 0; i < 4; i++)
            {
                var x = firstX;
                var y = firstY;
                if (i == 1)
                {
                    x += size;
                }

                if (i == 2)
                {
                    y += size;
                }
                if (i == 3)
                {
                    x += size;
                    y += size;
                }

                var sectionX = Netplay.GetSectionX(x);
                var sectionY = Netplay.GetSectionY(y);
                if (this.TileSections[sectionX, sectionY])
                {
                    return(true);
                }
            }
            return(false);
        }
 public bool Remove(object Key, bool Cleanup = true)
 {
     lock (Locker)
     {
         if (!Data.ContainsKey(Key))
         {
             return(false);
         }
         FakeTileRectangle o = Data[Key];
         Data.Remove(Key);
         Order.Remove(Key);
         int x = o.X, y = o.Y;
         int w = o.Width, h = o.Height;
         int sx = Netplay.GetSectionX(x), sy = Netplay.GetSectionY(y);
         int ex = Netplay.GetSectionX(x + w - 1), ey = Netplay.GetSectionY(y + h - 1);
         o.Tile.Dispose();
         if (Cleanup)
         {
             GC.Collect();
         }
         NetMessage.SendData((int)PacketTypes.TileSendSection,
                             -1, -1, null, x, y, w, h);
         NetMessage.SendData((int)PacketTypes.TileFrameSection,
                             -1, -1, null, sx, sy, ex, ey);
         return(true);
     }
 }
Example #13
0
 public void BackToOriginMap()
 {
     try
     {
         if (MapUUID != Guid.Empty && Map != null)
         {
             Map.Player.Remove(ID);
         }
         LeaveMap(Map);
         MapUUID = Guid.Empty;
         tsp.SendData(PacketTypes.WorldInfo, "", 0, 0f, 0f, 0f, 0);
         int sectionX  = Netplay.GetSectionX(0);
         int sectionX2 = Netplay.GetSectionX(Main.maxTilesX);
         int sectionY  = Netplay.GetSectionY(0);
         int sectionY2 = Netplay.GetSectionY(Main.maxTilesY);
         for (int i = sectionX; i <= sectionX2; i++)
         {
             for (int j = sectionY; j <= sectionY2; j++)
             {
                 Netplay.Clients[Index].TileSections[i, j] = false;
             }
         }
         tsp.Teleport(SpawnX, SpawnY);
         UserManager.UpdateInfoToOtherPlayers(this);
         MapManager.SendProjectile(this);
         MapManager.SendAllItem(this);
     }
     catch (Exception ex) { Log.Error(ex); }
 }
Example #14
0
        public void ResetSection()
        {
            int left = Math.Min(x, x2), right = Math.Max(x, x2);
            int top = Math.Min(y, y2), bottom = Math.Max(y, y2);
            int sX = Netplay.GetSectionX(left), sX2 = Netplay.GetSectionX(right);
            int sY = Netplay.GetSectionY(top), sY2 = Netplay.GetSectionY(bottom);

            int  w = (right - left + 1), h = (bottom - top + 1);
            bool SendWholeSections = ((w > 200) || (h > 150));

            if (SendWholeSections)
            {
                foreach (RemoteClient sock in Netplay.Clients.Where(s => s.IsActive))
                {
                    for (int i = sX; i <= sX2; i++)
                    {
                        for (int j = sY; j <= sY2; j++)
                        {
                            sock.TileSections[i, j] = false;
                        }
                    }
                }
            }
            else
            {
                NetMessage.SendData(10, -1, -1, null, left, top, w, h);
                NetMessage.SendData(11, -1, -1, null, sX, sY, sX2, sY2);
            }
        }
Example #15
0
 public void DirectConnection()
 {
     Netplay.ListenPort = _port;
     Netplay.SetRemoteIP("127.0.0.1");
     Netplay.Connection.Socket.Close();
     Netplay.StartTcpClient();
 }
Example #16
0
        public static void CheckSection(int who, Vector2 position, int fluff = 1)
        {
            int sectionX = Netplay.GetSectionX((int)(position.X / 16f));
            int sectionY = Netplay.GetSectionY((int)(position.Y / 16f));
            int num      = 0;

            for (int i = sectionX - 1; i < sectionX + 2; i++)
            {
                for (int j = sectionY - 1; j < sectionY + 2; j++)
                {
                    if (i >= 0 && i < Main.maxSectionsX && j >= 0 && j < Main.maxSectionsY && !Terraria.Netplay.Clients[who].TileSections[i, j])
                    {
                        num++;
                    }
                }
            }
            if (num > 0)
            {
                int num2 = num;
                NewNetMessage.SendData(9, who, -1, Lang.inter[44], num2, 0f, 0f, 0f, 0);
                Terraria.Netplay.Clients[who].StatusText2 = "is receiving tile data";
                Terraria.Netplay.Clients[who].StatusMax  += num2;
                for (int k = sectionX - 1; k < sectionX + 2; k++)
                {
                    for (int l = sectionY - 1; l < sectionY + 2; l++)
                    {
                        if (k >= 0 && k < Main.maxSectionsX && l >= 0 && l < Main.maxSectionsY && !Terraria.Netplay.Clients[who].TileSections[k, l])
                        {
                            NewNetMessage.SendSection(who, k, l, false);
                            NewNetMessage.SendData(11, who, -1, String.Empty, k, (float)l, (float)k, (float)l, 0);
                        }
                    }
                }
            }
        }
Example #17
0
        private void OnLobbyEntered(LobbyEnter_t result, bool failure)
        {
            //IL_001e: Unknown result type (might be due to invalid IL or missing references)
            //IL_002c: Unknown result type (might be due to invalid IL or missing references)
            //IL_0082: Unknown result type (might be due to invalid IL or missing references)
            //IL_0094: Unknown result type (might be due to invalid IL or missing references)
            //IL_00a4: Unknown result type (might be due to invalid IL or missing references)
            //IL_00b2: Unknown result type (might be due to invalid IL or missing references)
            //IL_00ca: Unknown result type (might be due to invalid IL or missing references)
            //IL_00db: Unknown result type (might be due to invalid IL or missing references)
            //IL_0127: Unknown result type (might be due to invalid IL or missing references)
            WeGameHelper.WriteDebugString(" OnLobbyEntered");
            SteamNetworking.AllowP2PPacketRelay(true);
            SendAuthTicket(_lobby.Owner);
            int num = 0;
            P2PSessionState_t val = default(P2PSessionState_t);

            while (SteamNetworking.GetP2PSessionState(_lobby.Owner, ref val) && val.m_bConnectionActive != 1)
            {
                switch (val.m_eP2PSessionError)
                {
                case 2:
                    ClearAuthTicket();
                    return;

                case 1:
                    ClearAuthTicket();
                    return;

                case 3:
                    ClearAuthTicket();
                    return;

                case 5:
                    ClearAuthTicket();
                    return;

                case 4:
                    if (++num > 5)
                    {
                        ClearAuthTicket();
                        return;
                    }
                    SteamNetworking.CloseP2PSessionWithUser(_lobby.Owner);
                    SendAuthTicket(_lobby.Owner);
                    break;
                }
            }
            _connectionStateMap[_lobby.Owner] = ConnectionState.Connected;
            SteamFriends.SetPlayedWith(_lobby.Owner);
            SteamFriends.SetRichPresence("status", Language.GetTextValue("Social.StatusInGame"));
            Main.clrInput();
            Netplay.ServerPassword = "";
            Main.GetInputText("");
            Main.autoPass = false;
            Main.netMode  = 1;
            Netplay.OnConnectedToSocialServer(new SocialSocket(new SteamAddress(_lobby.Owner)));
        }
Example #18
0
        //

        /// <summary>
        /// Handles calling and queuing requests to teleport a player to X,Y coords.
        /// </summary>
        /// <param name="x">X coord</param>
        /// <param name="y">Y coord</param>
        /// <param name="targetId">The target Player ID</param>
        public static void teleportPlayer(int x, int y, int targetId, bool old = true)
        {
            while (x % 2 != 0)
            {
                x++;
            }
            while (y % 2 != 0)
            {
                y++;
            }

            if (x > Main.maxTilesX - 2 || y > Main.maxTilesY - 2)
            {
                Commands.SendChatMsg("Landmark out of range, or coords off-map.", targetId, Color.Purple);
                return;
            }

            int sectionX = Netplay.GetSectionX(x);
            int sectionY = Netplay.GetSectionY(y + 1);

            /*
             * //does player already have the tilesection available to it? if yes, just teleport without queue
             * if (Netplay.serverSock[targetId].tileSection[sectionX, sectionY])
             * {
             *  TeleportToLocation(targetId, x, y + 1);
             *  return;
             * }*/

            Commands.SendChatMsg("Preparing teleport!", targetId, Color.Bisque);

            for (int m = sectionX - 1; m < sectionX + 2; m++)
            {
                for (int n = sectionY - 1; n < sectionY + 1; n++)
                {
                    NetMessage.SendSection(targetId, m, n);
                }
            }

            //additional section update details, 11 requests client determines tile frames and walls.
            NetMessage.SendData(11, targetId, -1, "", sectionX - 2, (float)(sectionY - 1), (float)(sectionX + 2), (float)(sectionY + 1), 0);

            teleQueue.AddLast(new TP {
                targetId = targetId, x = x, y = y + 1
            });

            //if timer hasn't been created, create and initialize
            if (tTimer == null)
            {
                tTimer          = new System.Timers.Timer(3000);
                tTimer.Elapsed += new ElapsedEventHandler(TeleportQueueProcess);
                tTimer.Enabled  = true;
            }
            else
            {   //else just enable it
                tTimer.Enabled = true;
            }
        }
Example #19
0
 public override void OnEnterWorld(Player player)
 {
     if (Main.netMode == 1)
     {
         currentConnectedAdress = Netplay.Connection.Socket.GetRemoteAddress();
         port     = Netplay.ListenPort;
         hostName = Netplay.GetLocalIPAddress();
     }
 }
Example #20
0
        public static void UpdateTile(int x, int y)
        {
            x = Netplay.GetSectionX(x);
            y = Netplay.GetSectionY(y);

            foreach (QPlayer ply in QMain.Players)
            {
                Netplay.serverSock[ply.Index].tileSection[x, y] = false;
            }
        }
        private void OnLobbyEntered(LobbyEnter_t result, bool failure)
        {
            SteamNetworking.AllowP2PPacketRelay(true);
            this.SendAuthTicket(this._lobby.Owner);
            var num = 0;
            P2PSessionState_t p2PsessionStateT;

            while (SteamNetworking.GetP2PSessionState(this._lobby.Owner, out p2PsessionStateT) &&
                   p2PsessionStateT.m_bConnectionActive != 1)
            {
                switch ((byte)p2PsessionStateT.m_eP2PSessionError)
                {
                case 1:
                    this.ClearAuthTicket();
                    return;

                case 2:
                    this.ClearAuthTicket();
                    return;

                case 3:
                    this.ClearAuthTicket();
                    return;

                case 4:
                    if (++num > 5)
                    {
                        this.ClearAuthTicket();
                        return;
                    }

                    SteamNetworking.CloseP2PSessionWithUser(this._lobby.Owner);
                    this.SendAuthTicket(this._lobby.Owner);
                    continue;

                case 5:
                    this.ClearAuthTicket();
                    return;

                default:
                    continue;
                }
            }

            this._connectionStateMap[this._lobby.Owner] = NetSocialModule.ConnectionState.Connected;
            SteamFriends.SetPlayedWith(this._lobby.Owner);
            SteamFriends.SetRichPresence("status", Language.GetTextValue("Social.StatusInGame"));
            Main.clrInput();
            Netplay.ServerPassword = "";
            Main.GetInputText("");
            Main.autoPass = false;
            Main.netMode  = 1;
            Netplay.OnConnectedToSocialServer(
                (ISocket) new SocialSocket((RemoteAddress) new SteamAddress(this._lobby.Owner)));
        }
 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();
     }
 }
Example #23
0
        public void Load()
        {
            //Dimlibs.Instance.Logger.Info("Is chat socket open? " + IsChatOpen());

            Dimlibs.Instance.Logger.Info("Chat is initializing");

            try
            {
                if (!Program.LaunchParameters.ContainsKey("-chat"))
                {
                    TcpListener listener = new TcpListener(IPAddress.Any, _port);
                    listener.Start();
                    ThreadPool.QueueUserWorkItem(InitializeChatRelay, listener);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }

            while (true)
            {
                if (_socket != null && _socket.IsConnected())
                {
                    break;
                }
            }



            if (Main.netMode == 2)
            {
                On.Terraria.Net.NetManager.SendToServer += NetManagerOnSendToServer;
                _socket = new TcpSocket();
                Netplay.SetRemoteIP("127.0.0.1");
                _socket.Connect(new Terraria.Net.TcpAddress(Netplay.ServerIP, _port));
                connection            = new RemoteServer();
                connection.Socket     = _socket;
                connection.ReadBuffer = new byte[ushort.MaxValue];
            }
            else
            {
                On.Terraria.Net.NetManager.SendToClient += NetManagerOnSendToClient;
                _socket = new TcpSocket();
                Netplay.SetRemoteIP("127.0.0.1");
                _socket.Connect(new Terraria.Net.TcpAddress(Netplay.ServerIP, _port));
                connection            = new RemoteServer();
                connection.Socket     = _socket;
                connection.ReadBuffer = new byte[ushort.MaxValue];
            }

            Dimlibs.Instance.Logger.Info("Chat is initialized and ready to go");
        }
Example #24
0
        /// <summary>
        /// Bans the user for the specified reason and duration
        /// </summary>
        /// <param name="id"></param>
        /// <param name="reason"></param>
        /// <param name="duration"></param>
        public void Ban(string id, string reason, TimeSpan duration = default(TimeSpan))
        {
            // Check if already banned
            if (IsBanned(id))
            {
                return;
            }

            // Ban and kick user
            Netplay.AddBan(int.Parse(id));
            //if (IsConnected) Kick(reason); // TODO: Implement if possible
        }
Example #25
0
        /// <summary>
        /// Bans the user for the specified reason and duration
        /// </summary>
        /// <param name="reason"></param>
        /// <param name="duration"></param>
        public void Ban(string reason, TimeSpan duration = default(TimeSpan))
        {
            // Check already banned
            if (IsBanned)
            {
                return;
            }

            // Set to banned
            Netplay.AddBan(player.whoAmI);
            NetMessage.SendData(2, player.whoAmI, -1, reason);
        }
Example #26
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();
     }
 }
Example #27
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;
        }
Example #28
0
        public void Packet69(string text, int number, float number2, float number3, float number4, int number5)
        {
            Begin(Packet.CHEST_NAME_UPDATE);

            Netplay.GetSectionX((int)number2);
            Netplay.GetSectionY((int)number3);
            Short((short)number);
            Short((short)number2);
            Short((short)number3);
            String(text);

            End();
        }
Example #29
0
        /// <summary>
        /// Bans the user for the specified reason and duration
        /// </summary>
        /// <param name="reason"></param>
        /// <param name="duration"></param>
        public void Ban(string reason, TimeSpan duration = default(TimeSpan))
        {
            // Check if already banned
            if (IsBanned)
            {
                return;
            }

            // Ban and kick user
            Netplay.AddBan(player.whoAmI);
            if (IsConnected)
            {
                Kick(reason);
            }
        }
Example #30
0
        static HookResult OnAccepted(Terraria.Net.Sockets.ISocket client)
        {
            int slot = FindNextOpenClientSlot();

            if (slot != -1)
            {
                Netplay.Clients[slot].Reset();
                Netplay.Clients[slot].Socket = client;
            }
            if (FindNextOpenClientSlot() == -1)
            {
                Netplay.StopListening();
            }
            return(HookResult.Cancel);
        }