Beispiel #1
0
 private void BlockReceived(IBlockEvent obj)
 {
     if (obj.BlockEventId == BlockEventId.ClientInfo)//when we receive this we must send the player database with the current player in it and the info for the map to be loaded
     {
         var createPlayerEvent = new CreatePlayerEvent();
         createPlayerEvent.PlayerId    = 1;
         createPlayerEvent.PlayerIndex = 0;
         createPlayerEvent.PlayerName  = "LifeCoder";
         createPlayerEvent.IsAI        = false;
         createPlayerEvent.PlayerTeam  = 2;
         createPlayerEvent.SpawnGroup  = 0;
         SendEvent(createPlayerEvent);
         new MapInfoEvent(true).Transmit(this);
         Send();
         //now we wait until the client finished loading the map
         //top id is 6, which is NetworkEvent, bottom id is 2 which is loadLevelComplete in NetworkEvent
         RemoteEventManager.AddEventHandler(6, 2, OnClientLoadComplete);
     }
     else if (obj.BlockEventId == BlockEventId.ServerInfo)
     {
         Config.ServerInfo = obj;
     }
     else if (obj.BlockEventId == BlockEventId.MapList)
     {
     }
     else
     {
     }
 }
        public void CreatePlayerListener(CreatePlayerEvent createPlayerEvent)
        {
            var player  = PlayerManager.Instance.FindPlayerByConnectionId(createPlayerEvent.hid);
            var message = WsMessageBuilder.CreateWsMessage("public", _terrainLayer);

            _eventBus.Post(message);
        }
        public void LoginPlayerListener(LoginPlayerEvent loginPlayerEvent)
        {
            var connectionPlayer = PlayerManager.Instance.FindPlayerByConnectionId(loginPlayerEvent.ConnectionId);
            var player           = PlayerManager.Instance.FindPlayerById(loginPlayerEvent.PlayerId);

            if (player == null)
            {
                player = CreatePlayer(loginPlayerEvent, connectionPlayer);
            }
            else // Merge to old player
            {
                PlayerManager.Instance.RemovePlayer(connectionPlayer);
                player.PlayerWsService = connectionPlayer.PlayerWsService;
                player.ConnectionId    = connectionPlayer.ConnectionId;
            }

            var yourPlayerEvent = new YourPlayerEvent(player);

            player.PlayerWsService.SendPrivate(yourPlayerEvent);


            var createPlayerEvent = new CreatePlayerEvent(player);

            QueueEvents.Instance.Add(createPlayerEvent);
        }
    public override void OnEvent(CreatePlayerEvent evnt)
    {
        base.OnEvent(evnt);
        //rec

        BoltNetwork.Instantiate(BoltPrefabs.NetworkedBubbleController, new OnlineIndexToken()
        {
            onlineIndex = evnt.onlineIndex
        });
    }
 public override void SceneLoadRemoteDone(BoltConnection connection)
 {
     BoltConsole.Write("SceneLoadRemoteDone");
     base.SceneLoadRemoteDone(connection);
     //scene is loaded on the client, send him an event to create a test player with a specific onlineIndex
     if (BoltNetwork.isServer)
     {
         CreatePlayerEvent e = CreatePlayerEvent.Create(connection);
         e.onlineIndex = totalPlayers;
         totalPlayers++;
         e.Send();
     }
 }
        public IGameEvent ReadGameEvent(IBitStream stream, bool useOld = false)
        {
            uint eventId = 0;
            int  v3      = 127;//adjust value depending on game, 127 is for bf2 and bf2142
            int  v4      = 0;

            do
            {
                ++v4;
            }while (v3 > (1 << v4) - 1);//if the event amount defined above is 127 then the result will be 7, meaning we read 7 bits and those 7 bits are the event id
            eventId = stream.ReadBits((uint)v4);
            IGameEvent eventInstance;

            if (!useOld)
            {
                eventInstance = Config.EventRegistry.Trigger(eventId, stream);//dont use in development
            }
            else
            #region old
            {
                if (eventId == 1)
                {
                    eventInstance = new ChallengeEvent().DeSerialize(stream);
                }
                else if (eventId == 2)
                {
                    eventInstance = new ChallengeResponseEvent().DeSerialize(stream);
                }
                else if (eventId == 3)
                {
                    eventInstance = new ConnectionTypeEvent().DeSerialize(stream);
                }
                else if (eventId == 4)
                {
                    eventInstance = new DataBlockEvent().DeSerialize(stream);
                }
                else if (eventId == 5)
                {
                    eventInstance = new CreatePlayerEvent().DeSerialize(stream);
                }
                else if (eventId == 6)
                {
                    eventInstance = new CreateObjectEvent().DeSerialize(stream);
                }
                else if (eventId == 8)
                {
                    eventInstance = new DestroyObjectEvent().DeSerialize(stream);
                }
                else if (eventId == 11)
                {
                    eventInstance = new PostRemoteEvent().DeSerialize(stream);
                }
                else if (eventId == 16)
                {
                    eventInstance = new StringBlockEvent().DeSerialize(stream);
                }
                else if (eventId == 31)
                {
                    eventInstance = new CreateKitEvent().DeSerialize(stream);
                }
                else if (eventId == 35) //voip event
                {
                    stream.ReadBits(9); //just read so we can skip
                    eventInstance = null;
                }
                else if (eventId == 39)
                {
                    eventInstance = new VoteEvent().DeSerialize(stream);
                }
                else if (eventId == 42)
                {
                    eventInstance = new UnlockEvent().DeSerialize(stream);
                }
                else if (eventId == 46)
                {
                    eventInstance = new ContentCheckEvent().DeSerialize(stream);
                }
                else if (eventId == 50)
                {
                    eventInstance = null;
                }
                else if (eventId == 54)    //voip event, we dont care
                {
                    stream.ReadBits(0x10); //just read so we can skip
                    eventInstance = null;
                }
                else if (eventId == 56)
                {
                    eventInstance = new BeginRoundEvent().DeSerialize(stream);
                }
                else if (eventId == 57)
                {
                    eventInstance = new CreateSpawnGroupEvent().DeSerialize(stream);
                }
                else
                {
                    eventInstance = null;
                }
            }
            #endregion
            return(eventInstance);
        }