public void OnEvent(ExitGames.Client.Photon.EventData eventData) { if (eventData.Code == NetworkManager.PlayerInputUpdate) { try { PlayerInputPacket data = eventData.CustomData as PlayerInputPacket; if (data != null && data.PlayerIndex == PlayerIndex) { foreach (PlayerInputData inputFrame in data.InputData) { // FrameNumber == 0: Initial packet of round. Should be okay to ACK. if (inputFrame.RoundNumber == GameStateManager.Instance.RoundCount && CommandInterpreter.QueuePlayerInput(inputFrame)) { SendInputAck(inputFrame.PacketId); } } } } catch (Exception e) { Debug.LogError(e); } } }
public void SendInput(PlayerInputData input, bool addDataToList) { // If we are currently synchronizing the game state by catching up to the highest frame, do not send off any inputs. if (Overseer.Instance.GameReady && !NetworkManager.Instance.IsSynchronizing) { PlayerInputPacket packetToSend = new PlayerInputPacket(); packetToSend.FrameSent = GameStateManager.Instance.FrameCount; packetToSend.PlayerIndex = PlayerController.PlayerIndex; if (addDataToList) { input.PacketId = PacketsSent; DataSent.Add(input); ++PacketsSent; } packetToSend.InputData = DataSent; float rand = Random.Range(0.0f, 1.0f); if (rand <= NetworkManager.Instance.SendPercentage) { NetworkManager.Instance.SendEventData(NetworkManager.PlayerInputUpdate, packetToSend, ReceiverGroup.Others, true); } } }
void Start() { if (!gameObject.GetPhotonView().isMine) { Destroy(this); } else { ID = PhotonNetwork.player.ID; roomName = PhotonNetwork.room.Name; inputList = new List <PlayerInputPacket>(); fakeInputer = GetComponent <FakeInputer>(); inputPacket = new PlayerInputPacket(); isMasterClient = PhotonNetwork.isMasterClient; inputPacket.isMasterClient = isMasterClient; inputPacket.playerID = ID; inputPacket.roomName = roomName; inputPacket.x = 0; inputPacket.y = 0; ipep = new IPEndPoint(IPAddress.Parse("192.168.137.242"), 6666); udpClient = new UdpClient(); connectThread = new Thread(new ThreadStart(TryReceive)); connectThread.Start(); } }
public static short Serialize(StreamBuffer outstream, object data) { PlayerInputPacket inputData = (PlayerInputPacket)data; string inputDataListJson = JsonConvert.SerializeObject(inputData.InputData); Encoding encoder = Encoding.UTF8; byte[] stringToByte = encoder.GetBytes(inputDataListJson); int stringSize = stringToByte.Length; int byteArrayIndex = 0; byte[] obj = new byte[DataSize + stringSize]; Protocol.Serialize((int)inputData.FrameSent, obj, ref byteArrayIndex); Protocol.Serialize((int)inputData.PacketId, obj, ref byteArrayIndex); Protocol.Serialize(inputData.PlayerIndex, obj, ref byteArrayIndex); Protocol.Serialize(stringSize, obj, ref byteArrayIndex); System.Array.Copy(stringToByte, 0, obj, byteArrayIndex, stringToByte.Length); outstream.Write(obj, 0, DataSize + stringSize); return((short)(stringSize + DataSize)); }
public static object Deserialize(StreamBuffer inStream, short length) { PlayerInputPacket inputPacket = new PlayerInputPacket(); byte[] output = new byte[DataSize]; inStream.Read(output, 0, DataSize); int index = 0; int frameSent; int packetId; int stringSize; Protocol.Deserialize(out frameSent, output, ref index); inputPacket.FrameSent = (uint)frameSent; Protocol.Deserialize(out packetId, output, ref index); inputPacket.PacketId = (uint)packetId; Protocol.Deserialize(out inputPacket.PlayerIndex, output, ref index); Protocol.Deserialize(out stringSize, output, ref index); byte[] customString = new byte[stringSize]; inStream.Read(customString, 0, stringSize); string jsonString = Encoding.UTF8.GetString(customString); List <PlayerInputData> inputList = JsonConvert.DeserializeObject <List <PlayerInputData> >(jsonString); inputPacket.InputData = inputList; return(inputPacket); }
public UpdatePacket processInput(PlayerInputPacket pip) { UpdatePacket update = new UpdatePacket(); update.playerID = pip.playerID; update.move = pip.move; return(update); }
public void SendPlayerInput(float[] playerInput, uint objectId, uint id) { PlayerInputPacket packet = new PlayerInputPacket(); packet.payload = playerInput; PacketManager.Instance.SendPacket(packet, objectId, packet.reliable, id); }
public PlayerInputPacket ByteArrayToNewStuff(byte[] bytes) { GCHandle handle = GCHandle.Alloc(bytes, GCHandleType.Pinned); PlayerInputPacket stuff = (PlayerInputPacket)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(PlayerInputPacket)); handle.Free(); return(stuff); }
public override void ApplyInput(PlayerInputPacket command, float delta) { if (NetworkGeneral.SeqDiff(command.Id, LastProcessedCommandId) <= 0) { return; } LastProcessedCommandId = command.Id; base.ApplyInput(command, delta); }
void OnReceivePacket(ushort type, Stream stream) { switch (type) { case (ushort)UserPacketType.TimedPosition: PlayerInputPacket playerInput = new PlayerInputPacket(); idReceived = playerInput.Deserialize(stream); OnFinishDeserializing(PlayerPositionReconciliationChecker, playerInput.payload); //SetPlayerPosition(playerInput.payload); break; } }
public byte[] getBytes(PlayerInputPacket str) { int size = Marshal.SizeOf(str); byte[] arr = new byte[size]; IntPtr ptr = Marshal.AllocHGlobal(size); Marshal.StructureToPtr(str, ptr, true); Marshal.Copy(ptr, arr, 0, size); Marshal.FreeHGlobal(ptr); return(arr); }
public void SendHeartbeat() { PlayerInputPacket packet = new PlayerInputPacket(); packet.FrameSent = GameStateManager.Instance.FrameCount; packet.PlayerIndex = PlayerController.PlayerIndex; packet.InputData = DataSent; float rand = Random.Range(0.0f, 1.0f); if (rand <= NetworkManager.Instance.SendPercentage) { NetworkManager.Instance.SendEventData(NetworkManager.PlayerInputUpdate, packet, ReceiverGroup.Others, true); } }
public void BlockFreezeStateUpdate() { lobbyManager.createLobby(4, "bob", 5, "no", (WebSocketSharp.WebSocket)null, "five"); LobbyInfoPacket lip = lobbyManager.joinLobby("testing", 1, "bob", "no"); Packet packet = new Packet(); packet.data = "{'lobbyID': 'five'}"; packet.type = 2; lobbyManager.startGame(packet); PlayerInputPacket pip = new PlayerInputPacket(); pip.lobbyID = "five"; pip.move = "freeze"; int[][] indices = new int[][] { new int[] { 1, 2 } }; pip.shapeIndices = indices; UpdatePacket up = lobbyManager.processInput(pip); }
public void GameStateAlert() { lobbyManager.createLobby(4, "bob", 5, "no", (WebSocketSharp.WebSocket)null, "five"); LobbyInfoPacket lip = lobbyManager.joinLobby("testing", 1, "bob", "no"); Packet packet = new Packet(); packet.data = "{'lobbyID': 'five'}"; packet.type = 2; lobbyManager.startGame(packet); PlayerInputPacket pip = new PlayerInputPacket(); pip.lobbyID = "five"; pip.move = "left"; UpdatePacket up = lobbyManager.processInput(pip); Assert.That(up.move == "left"); }
public void OnEvent(EventData photonEvent) { if (photonEvent.Code == NetworkManager.PlayerInputAck) { int packetNumber = (int)photonEvent.CustomData; HandlePlayerInputAck((uint)packetNumber); } else if (photonEvent.Code == NetworkManager.PlayerInputUpdate) { PlayerInputPacket packet = photonEvent.CustomData as PlayerInputPacket; if (packet != null) { if (packet.FrameSent > HighestFrameCountReceived) { HighestFrameCountReceived = packet.FrameSent; uint newFrameLimit = packet.FrameSent + (uint)NetworkManager.Instance.TotalDelayFrames; ResetFrameWaitTime(newFrameLimit); } } } }
public override void ApplyInput(PlayerInputPacket command, float delta) { LastProcessedCommandId = command.Id; base.ApplyInput(command, delta); }
public void sendRaycast(RaycastInfo info) { if (Aim.EnableAimbot && Aim.AimSilent && Aim.target != null) { Vector3 normal = (Aim.GetLimbPosition(Aim.target, "Skull") - Player.player.look.aim.position).normalized; info = DamageTool.raycast(new Ray(Player.player.look.aim.position, normal), 512f, RayMasks.DAMAGE_CLIENT); } if (Provider.isServer) // doesnt mess up singleplayer { InputInfo inputInfo = new InputInfo(); inputInfo.animal = info.animal; inputInfo.direction = info.direction; inputInfo.limb = info.limb; inputInfo.material = info.material; inputInfo.normal = info.normal; inputInfo.player = info.player; inputInfo.point = info.point; inputInfo.transform = info.transform; inputInfo.vehicle = info.vehicle; inputInfo.zombie = info.zombie; inputInfo.section = info.section; if (inputInfo.player != null) { inputInfo.type = ERaycastInfoType.PLAYER; } else if (inputInfo.zombie != null) { inputInfo.type = ERaycastInfoType.ZOMBIE; } else if (inputInfo.animal != null) { inputInfo.type = ERaycastInfoType.ANIMAL; } else if (inputInfo.vehicle != null) { inputInfo.type = ERaycastInfoType.VEHICLE; } else if (inputInfo.transform != null) { if (inputInfo.transform.CompareTag("Barricade")) { inputInfo.type = ERaycastInfoType.BARRICADE; } else if (info.transform.CompareTag("Structure")) { inputInfo.type = ERaycastInfoType.STRUCTURE; } else if (info.transform.CompareTag("Resource")) { inputInfo.type = ERaycastInfoType.RESOURCE; } else if (inputInfo.transform.CompareTag("Small") || inputInfo.transform.CompareTag("Medium") || inputInfo.transform.CompareTag("Large")) { inputInfo.type = ERaycastInfoType.OBJECT; } else if (info.transform.CompareTag("Ground") || info.transform.CompareTag("Environment")) { inputInfo.type = ERaycastInfoType.NONE; } else { inputInfo = null; } } else { inputInfo = null; } if (inputInfo != null) { Queue <InputInfo> inputs = (Queue <InputInfo>)Player.player.input.GetType().GetField("inputs").GetValue(Player.player.input); inputs.Enqueue(inputInfo); } } else { PlayerInputPacket playerInputPacket = GetLatestPacket(); if (playerInputPacket.clientsideInputs == null) { playerInputPacket.clientsideInputs = new List <RaycastInfo>(); } if (Aim.EnableAimbot && Aim.AimSilent && Aim.target != null) { var player = Tools.GetPlayerFromTransform(Aim.target); if (player != null) { info.player = player; info.limb = ELimb.SKULL; } } playerInputPacket.clientsideInputs.Add(info); } }
public void SendPlayerInput(PlayerInputPacket playerInputPacket) { playerInputPacket.ServerTick = _lastServerTick; SendPacketSerializable(PacketType.Movement, playerInputPacket, DeliveryMethod.Unreliable); }
protected override void OnMessage(MessageEventArgs e) { // Console.WriteLine(e.Data); Packet packet = JsonConvert.DeserializeObject <Packet>(e.Data); string socketID = ID; // join packet -- 0 if (packet.type == Packets.JOIN) { JoinPacket jPacket = JsonConvert.DeserializeObject <JoinPacket>(packet.data); joinLobby(jPacket.lobbyID, jPacket.playerID, jPacket.name, socketID); } // create packet -- 1 else if (packet.type == Packets.CREATE) { try { Console.WriteLine("making new create packet"); // Create a lobby with given parameters CreatePacket createPacket = JsonConvert.DeserializeObject <CreatePacket>(packet.data); createLobby(createPacket.maxPlayers, createPacket.name, createPacket.playerID, socketID, Context.WebSocket); } catch (NullReferenceException nre) { Console.WriteLine("hi"); Console.WriteLine(nre); } } // start packet -- 2 else if (packet.type == 2) { startGame(packet); } else if (packet.type == Packets.PLAYER_INPUT) { PlayerInputPacket playerInputPacket = JsonConvert.DeserializeObject <PlayerInputPacket>(packet.data); Player currentPlayer = null; foreach (Player player in lobbies[playerInputPacket.lobbyID].players) { if (player.socketID == ID) { currentPlayer = player; } } if (currentPlayer == null) { // no valid player found in lobby return; } // validate move foreach (Player player in lobbies[playerInputPacket.lobbyID].players) { if (player.socketID != ID) { if (player.currentBlockPosition != null) { foreach (int[] pos1 in player.currentBlockPosition) { foreach (int[] pos2 in playerInputPacket.shapeIndices) { if (pos1 == pos2) { Send("COLLISION"); return; } } } } } } UpdatePacket update = processInput(playerInputPacket); if (playerInputPacket.move != "freeze") { currentPlayer.currentBlockPosition = playerInputPacket.shapeIndices; playerInputPacket.playerID = currentPlayer.id; foreach (Player player in lobbies[playerInputPacket.lobbyID].players) { if (player.socketID != ID) { Sessions.SendTo(JsonConvert.SerializeObject(update), player.socketID); } } } else { // remove column is ID # 2 // remove area is ID # 3 // area removes 2 up, 2 left, 2 right, 2 down Lobby lobby = lobbies[playerInputPacket.lobbyID]; update.shapeIndices = playerInputPacket.shapeIndices; foreach (int[] pos in playerInputPacket.shapeIndices) { // FREEZE lobby.game.board.board[pos[0], pos[1]] = pos[2]; } // Prints prints = new Prints(); // Console.WriteLine("LOBBY BOARD"); // prints.PrintMultiDimArr(lobby.game.board.board); checkRows(lobby); foreach (Player player in lobby.players) { if (player.socketID != ID) { Sessions.SendTo(JsonConvert.SerializeObject(update), player.socketID); } } } // on place piece put on board ;GJ } else if (packet.type == Packets.BOT_UPDATE) // 7 { BotPacket bot = JsonConvert.DeserializeObject <BotPacket>(packet.data); if (bot.action == 1) { lobbies[bot.lobbyID].botCount++; lobbies[bot.lobbyID].numPlayers++; alertLobby(-2, bot.lobbyID, Packets.ADD_BOT); } else if (bot.action == 0) { lobbies[bot.lobbyID].botCount--; lobbies[bot.lobbyID].numPlayers--; alertLobby(-2, bot.lobbyID, Packets.REMOVE_BOT); } } else if (packet.type == Packets.SHAPE_BLUEPRINT) { ShapeBlueprintPacket sbp = JsonConvert.DeserializeObject <ShapeBlueprintPacket>(packet.data); foreach (Player player in lobbies[sbp.lobbyID].players) { if (player.socketID != ID) { Sessions.SendTo(JsonConvert.SerializeObject(sbp), player.socketID); } else { //player.currentBlock = sbp.shapeBlueprint; } } } else if (packet.type == Packets.TEAM_NAME) { // format the packet to be a scors packet with all the team information TeamPacket tPacket = JsonConvert.DeserializeObject <TeamPacket>(packet.data); foreach (Player player in lobbies[tPacket.lobbyid].players) { if (player.socketID != ID) { Sessions.SendTo(JsonConvert.SerializeObject(tPacket), player.socketID); } else { //player.currentBlock = sbp.shapeBlueprint; } } } else if (packet.type == Packets.GAME_END) { EndPacket end = JsonConvert.DeserializeObject <EndPacket>(packet.data); if (checkGameEnd(end)) { foreach (Player player in lobbies[end.lobbyID].players) { Sessions.SendTo(JsonConvert.SerializeObject(end), player.socketID); } } } else if (packet.type == Packets.POS_UPDATE) { PositionPacket pp = JsonConvert.DeserializeObject <PositionPacket>(packet.data); foreach (Player player in lobbies[pp.lobbyID].players) { if (player.socketID == ID) { player.currentBlockPosition = pp.shapeIndices; } } } else { Console.WriteLine("bad packet"); Console.WriteLine(packet.type); Send("bad packet!!! :("); } }
public override void ApplyInput(PlayerInputPacket command, float delta) { base.ApplyInput(command, delta); }