Пример #1
0
 public Player(ServerHandle handle, int id, Router router)
 {
     this.handle = handle;
     this.id     = id;
     this.router = router;
     exists      = true;
     viewArea    = new ViewArea(0, 0, 1920 / 2 * handle.Settings.playerViewScaleMult, 1080 / 2 * handle.Settings.playerViewScaleMult, 1);
 }
Пример #2
0
 private void OnTriggerEnter(Collider other)
 {
     if (other.CompareTag("Avatar") && Client.instance.host)
     {
         int _player = other.GetComponent <PlayerManager>().id;
         ServerHandle.pickupItem(_player, id, itemNumber);
     }
 }
Пример #3
0
 /// <summary>
 /// 构造函数
 /// </summary>
 /// <param name="tcpServerConfig"></param>
 /// <param name="accreditHandle"></param>
 /// <param name="iLog"></param>
 public TcpServerHost(TcpServerConfig tcpServerConfig, ServerHandle accreditHandle, ITcpServerLog iLog = null)
 {
     _iLog = iLog;
     _accreditHandle = accreditHandle;
     //SessionFactory = sessionFactory;
     _tcpServerConfig = tcpServerConfig;
     _tokenPool = new UserTokenPool();
 }
Пример #4
0
 public Listener(ServerHandle handle)
 {
     listenerSocket = new WebSocket()
     {
         NoDelay = false
     };
     globalChat  = new ChatChannel(this);
     this.handle = handle;
 }
Пример #5
0
 /// <summary>
 /// Gets a gamemode bast off of its name, it is not case sensitive.
 /// </summary>
 /// <param name="handle"></param>
 /// <param name="name"></param>
 /// <returns></returns>
 public static Gamemode GetGamemode(this ServerHandle handle, string name)
 {
     if (gamemodes.TryGetValue(name.ToLower(), out Func <ServerHandle, Gamemode> gamemode))
     {
         return(gamemode(handle));
     }
     else
     {
         throw new Exception($"Gamemode '{name}' does not exist");
     }
 }
Пример #6
0
        /// <summary>
        /// Gets a gamemode based off of its type.
        /// </summary>
        /// <typeparam name="T">The gamemode type.</typeparam>
        /// <param name="handle"></param>
        /// <returns></returns>
        public static T GetGamemode <T>(this ServerHandle handle) where T : Gamemode
        {
            var gamemodename = typeof(T).Name;

            if (gamemodes.TryGetValue(gamemodename.ToLower(), out Func <ServerHandle, Gamemode> gamemode))
            {
                return((T)gamemode(handle));
            }
            else
            {
                throw new Exception($"Gamemode '{gamemodename}' does not exist");
            }
        }
Пример #7
0
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="tcpServerConfig"></param>
        /// <param name="accreditHandle"></param>
        /// <param name="iLog"></param>
        public TcpServerHost(TcpServerConfig tcpServerConfig, ServerHandle accreditHandle, ITcpServerLog iLog = null)
        {
            _isRun = false;

            _iLog = iLog;
            _accreditHandle = accreditHandle;
            //SessionFactory = sessionFactory;
            _tcpServerConfig = tcpServerConfig;
            _tokenPool = new UserTokenPool();

            var period = 60;

            recordThreads = new Thread(() => 
            {
                while (true)
                {
                    foreach (var _ut in _tokenPool.userTokens)
                    {
                        var _token = _ut.Value;
                        if (_token == null || _token.Socket == null || !_token.Socket.Connected
                            || _token.ActivityTime.AddHours(5) < DateTime.Now)
                        {
                            _tokenPool.RemoveUserToken(_token.Identity);
                            _token.Close();
                        }
                    }
                    //_tokenPool.RemoveUserToken(_token.Identity);
                    //_token.Close();

                    string msg = string.Format("bits per second: {0:N2}\r\nsend count per second: {1:N2}\r\nreceive count per second: {2:N2}\r\nsession count: {3}",
                       totalBytes / (double)period,
                       sendCount / (double)period,
                       receiveCount / (double)period, UserTokenCount());
                    totalBytes = 0;
                    sendCount = 0;
                    receiveCount = 0;
                    _iLog.LogInfo(msg, "record.txt");

                    Thread.Sleep(period * 1000);
                }
            });
            recordThreads.IsBackground = true;
            recordThreads.Start();

        }
Пример #8
0
        private static void InitalizeServer()
        {
            Slots = new Dictionary <int, ClientObject>();

            ServerHandle.InitializeServerPacketHandlers();

            for (var i = 1; i <= Config.MAX_PLAYERS; i++)
            {
                Slots.Add(i, new ClientObject(i));
            }

            TcpListener = new TcpListener(IPAddress.Any, Config.PORT);
            TcpListener.Start();
            TcpListener.BeginAcceptTcpClient(new AsyncCallback(TcpConnectCallback), null);

            UdpListener = new UdpClient(Config.PORT);
            UdpListener.BeginReceive(UdpReceiveCallback, null);
        }
	public static void StartServer(int maxPlayers, int port)
	{
		MaxPlayers = maxPlayers;
		Port = port;

		Console.WriteLine("[Server] Starting server...");
		Console.WriteLine($"[Server] IP: 127.0.0.1\n[Server] Port: {Port}\n");

		InitializeServerData();

		ServerHandle.InitializeServerData();
		
		_tcpListener = new TcpListener(IPAddress.Parse("127.0.0.1"), Port);
		_tcpListener.Start();
		_tcpListener.BeginAcceptTcpClient(new AsyncCallback(TCPConnectCallback), null);

		_udpListener = new UdpClient(Port);
		_udpListener.BeginReceive(UDPReceiveCallback, null);

		Console.WriteLine($"[Server] Server started on {Port}.");
	}
Пример #10
0
    private static void MessageReceived(object sender, MessageReceivedEventArgs e)
    {
        Packet packet  = new Packet(e.Data);
        Client client_ = FindClientByIpPort(e.IpPort);
        int    type    = packet.ReadInt();

        if (type == (int)ClientPackets.ping)
        {
            ServerHandle.Ping(client_.id, packet);
        }
        else
        {
            ThreadManager.ExecuteOnMainThread(() =>
            {
                byte[] packetData = e.Data;
                Packet _packet    = new Packet(packetData);
                int _packetId     = _packet.ReadInt();
                Client client     = FindClientByIpPort(e.IpPort);
                NetworkManager.AddPacket(client.id, _packetId, _packet);
            });
        }
    }
Пример #11
0
 public void ResetGame()
 {
     ServerHandle.Reset();
     resetScreen.SetActive(false);
 }
Пример #12
0
 public World(ServerHandle handle, int id)
 {
     this.handle = handle;
     this.id     = id;
     SetBorder(new RectangleF(Settings.worldMapX, Settings.worldMapY, Settings.worldMapW, Settings.worldMapH));
 }
Пример #13
0
 public PainterSender(LanCanvas lanCanvas, string name)
 {
     this.lanCanvas = lanCanvas;
     LocalName      = name;
     Handle         = new ServerHandle(this);
 }
Пример #14
0
 public Teams(ServerHandle handle) : base(handle)
 {
 }
Пример #15
0
 internal ServerQueueHandle(Connection connection, Packet receivedPacket, ServerHandle handle)
 {
     Connection     = connection;
     ReceivedPacket = receivedPacket;
     Handle         = handle;
 }
Пример #16
0
 public FFA(ServerHandle handle) : base(handle)
 {
 }
Пример #17
0
    void ProcessBuffer(Client client)
    {
        int end = buffer[client.id].Count;

        foreach (PacketData packet in buffer[client.id])
        {
            try
            {
                switch (packet.type)
                {
                /*case (int)ClientPackets.welcomeReceived:
                 *  ServerHandle.WelcomeReceived(client.id, packet.packet);
                 *  break;*/
                case (int)ClientPackets.login:
                    ServerHandle.Login(client.id, packet.packet);
                    break;

                case (int)ClientPackets.playerMovement:
                    ServerHandle.PlayerMovement(client.id, packet.packet);
                    break;

                case (int)ClientPackets.joystick:
                    ServerHandle.Joystick(client.id, packet.packet);
                    break;

                case (int)ClientPackets.position:
                    ServerHandle.Position(client.id, packet.packet);
                    break;

                case (int)ClientPackets.test:
                    ServerHandle.test(client.id, packet.packet);
                    break;

                case (int)ClientPackets.getInventory:
                    ServerHandle.GetInventory(client.id, packet.packet);
                    break;

                case (int)ClientPackets.dropItem:
                    ServerHandle.DropItem(client.id, packet.packet);
                    break;

                case (int)ClientPackets.dragAndDrop:
                    ServerHandle.DragAndDrop(client.id, packet.packet);
                    break;

                case (int)ClientPackets.searchChest:
                    ServerHandle.SearchChest(client.id, packet.packet);
                    break;

                case (int)ClientPackets.getShipEquipment:
                    ServerHandle.GetShipEquipment(client.id, packet.packet);
                    break;

                case (int)ClientPackets.replaceShipEquipment:
                    ServerHandle.ReplaceShipEquipment(client.id, packet.packet);
                    break;

                case (int)ClientPackets.unequipItem:
                    ServerHandle.UnequipItem(client.id, packet.packet);
                    break;

                case (int)ClientPackets.removeItemFromInventory:
                    ServerHandle.RemoveItemFromInventory(client.id, packet.packet);
                    break;

                case (int)ClientPackets.getPlayerEquipment:
                    ServerHandle.GetPlayerEquipment(client.id, packet.packet);
                    break;

                case (int)ClientPackets.replacePlayerEquipment:
                    ServerHandle.ReplacePlayerEquipment(client.id, packet.packet);
                    break;

                /*case (int)ClientPackets.onGameStart:
                 *  ServerHandle.OnGameStart(client.id, packet.packet);
                 *  break;*/
                case (int)ClientPackets.shoot:
                    ServerHandle.Shoot(client.id, packet.packet);
                    break;

                case (int)ClientPackets.cannonRotate:
                    ServerHandle.CannonRotate(client.id, packet.packet);
                    break;

                case (int)ClientPackets.collectLoot:
                    ServerHandle.CollectLoot(client.id, packet.packet);
                    break;

                case (int)ClientPackets.discardLoot:
                    ServerHandle.DiscardLoot(client.id, packet.packet);
                    break;

                case (int)ClientPackets.chatMessage:
                    ServerHandle.ChatMessage(client.id, packet.packet);
                    break;

                case (int)ClientPackets.createGroup:
                    ServerHandle.CreateGroup(client.id, packet.packet);
                    break;

                case (int)ClientPackets.getGroupList:
                    ServerHandle.GetGroupList(client.id, packet.packet);
                    break;

                case (int)ClientPackets.applyToGroup:
                    ServerHandle.ApplyToGroup(client.id, packet.packet);
                    break;

                case (int)ClientPackets.acceptGroupApplicant:
                    ServerHandle.AcceptGroupApplicant(client.id, packet.packet);
                    break;

                case (int)ClientPackets.declineGroupApplicant:
                    ServerHandle.DeclineGroupApplicant(client.id, packet.packet);
                    break;

                case (int)ClientPackets.kickGroupMember:
                    ServerHandle.KickGroupMember(client.id, packet.packet);
                    break;

                case (int)ClientPackets.leaveGroup:
                    ServerHandle.LeaveGroup(client.id, packet.packet);
                    break;

                case (int)ClientPackets.getPlayerList:
                    ServerHandle.GetPlayerList(client.id, packet.packet);
                    break;

                case (int)ClientPackets.invitePlayer:
                    ServerHandle.InvitePlayer(client.id, packet.packet);
                    break;

                case (int)ClientPackets.acceptGroupInvitation:
                    ServerHandle.AcceptGroupInvitation(client.id, packet.packet);
                    break;

                case (int)ClientPackets.declineGroupInvitation:
                    ServerHandle.DeclineGroupInvitation(client.id, packet.packet);
                    break;

                case (int)ClientPackets.leaveEnterShip:
                    ServerHandle.LeaveEnterShip(client.id, packet.packet);
                    break;

                case (int)ClientPackets.playerInputs:
                    ServerHandle.PlayerInputs(client.id, packet.packet);
                    break;

                case (int)ClientPackets.animationInputs:
                    ServerHandle.AnimationInputs(client.id, packet.packet);
                    break;

                case (int)ClientPackets.mouseX:
                    ServerHandle.MouseX(client.id, packet.packet);
                    break;

                case (int)ClientPackets.gatherResource:
                    ServerHandle.GatherResource(client.id, packet.packet);
                    break;

                case (int)ClientPackets.playerSkills:
                    ServerSend.PlayerSkills(client.id);
                    break;

                case (int)ClientPackets.craftSelected:
                    ServerHandle.CraftSelected(client.id, packet.packet);
                    break;

                case (int)ClientPackets.cancelCrafting:
                    ServerHandle.CancelCrafting(client.id, packet.packet);
                    break;

                case (int)ClientPackets.requestCrafting:
                    ServerHandle.RequestCrafting(client.id, packet.packet);
                    break;

                case (int)ClientPackets.traderInventoryRequest:
                    ServerHandle.TraderInventoryRequest(client.id, packet.packet);
                    break;

                case (int)ClientPackets.buyItem:
                    ServerHandle.BuyItem(client.id, packet.packet);
                    break;

                case (int)ClientPackets.sellItem:
                    ServerHandle.SellItem(client.id, packet.packet);
                    break;

                case (int)ClientPackets.tradeBrokerRequest:
                    ServerHandle.TradeBrokerRequest(client.id, packet.packet);
                    break;

                case (int)ClientPackets.readTradeBrokerItems:
                    ServerHandle.ReadTradeBrokerItems(client.id, packet.packet);
                    break;

                case (int)ClientPackets.registerItemOnBroker:
                    ServerHandle.RegisterItemOnBroker(client.id, packet.packet);
                    break;

                case (int)ClientPackets.removeItemFromBroker:
                    ServerHandle.RemoveItemFromBroker(client.id, packet.packet);
                    break;

                case (int)ClientPackets.buyItemFromBroker:
                    ServerHandle.BuyItemFromBroker(client.id, packet.packet);
                    break;

                case (int)ClientPackets.collectFromBroker:
                    ServerHandle.CollectFromBroker(client.id, packet.packet);
                    break;

                case (int)ClientPackets.tradeRequest:
                    ServerHandle.TradeRequest(client.id, packet.packet);
                    break;

                case (int)ClientPackets.acceptTrade:
                    ServerHandle.AcceptTrade(client.id, packet.packet);
                    break;

                case (int)ClientPackets.declineTrade:
                    ServerHandle.DeclineTrade(client.id, packet.packet);
                    break;

                case (int)ClientPackets.cancelPlayerTrade:
                    ServerHandle.CancelPlayerTrade(client.id, packet.packet);
                    break;

                case (int)ClientPackets.playerTradeAddItem:
                    ServerHandle.PlayerTradeAddItem(client.id, packet.packet);
                    break;

                case (int)ClientPackets.playerTradeRemoveItem:
                    ServerHandle.PlayerTradeRemoveItem(client.id, packet.packet);
                    break;

                case (int)ClientPackets.playerTradeGoldChanged:
                    ServerHandle.PlayerTradeGoldChanged(client.id, packet.packet);
                    break;

                case (int)ClientPackets.playerTradeAccept:
                    ServerHandle.PlayerTradeAccept(client.id, packet.packet);
                    break;

                case (int)ClientPackets.isOnShip:
                    ServerHandle.IsOnShip(client.id, packet.packet);
                    break;

                case (int)ClientPackets.switchTarget:
                    ServerHandle.SwitchTarget(client.id, packet.packet);
                    break;

                case (int)ClientPackets.playerCharacterPosition:
                    ServerHandle.PlayerCharacterPosition(client.id, packet.packet);
                    break;

                case (int)ClientPackets.jump:
                    ServerHandle.Jump(client.id, packet.packet);
                    break;

                case (int)ClientPackets.startCrafting:
                    ServerSend.StartCrafting(client.id);
                    break;

                case (int)ClientPackets.stopCrafting:
                    ServerSend.StopCrafting(client.id);
                    break;

                case (int)ClientPackets.shipPosition:
                    ServerHandle.ShipPosition(client.id, packet.packet);
                    break;

                case (int)ClientPackets.addBuff:
                    ServerHandle.AddBuff(client.id, packet.packet);
                    break;

                case (int)ClientPackets.animationTranslate:
                    ServerHandle.AnimationTranslate(client.id, packet.packet);
                    break;

                case (int)ClientPackets.ping:
                    ServerHandle.Ping(client.id, packet.packet);
                    break;

                case (int)ClientPackets.loadLoot:
                    ServerHandle.LoadLoot(client.id, packet.packet);
                    break;

                case (int)ClientPackets.switchWeaponHands:
                    ServerHandle.SwitchWeaponHands(client.id, packet.packet);
                    break;
                }
            }
            catch (Exception ex)
            {
                Debug.LogError("NetworkManager.cs ProcessBuffer(): " + ex.Message + " " + ex.StackTrace);
            }
        }

        buffer[client.id].RemoveRange(0, end);
    }
Пример #18
0
 public Gamemode(ServerHandle handle) => this.handle = handle;
Пример #19
0
 public void ScenarioTeardown()
 {
     ServerHandle.Dispose();
     ServerHandle = null;
 }
Пример #20
0
 public MatchMaker(ServerHandle handle)
 {
     this.handle = handle;
 }