Пример #1
0
        static void HandleGameData(HazelBinaryReader reader, GameDataType datatype, bool send)
        {
            var dir = send ? "SEND" : "RECV";

            switch (datatype)
            {
            case GameDataType.RpcCall:
                var RPC     = RpcCall.Deserialize(reader);
                var reciver = EntityTracker.Get(RPC.targetNetId);
                if (LogRPC)
                {
                    Console.WriteLine($"[RPC][{RPC.callId}]sent to {reciver?.GetType()?.Name ?? "unknown"} size: {reader.GetBytesLeft()}");
                }
                if (reciver != null)
                {
                    reciver.HandleRpcCall(RPC.callId, reader);
                }
                //DumpToConsole(RPC, LogRPC);
                //Console.WriteLine($"RPC for type: {RPC} size: {data.body.Length}");
                switch (RPC.callId)
                {
                case RpcCalls.CheckColor:
                    var CheckColor = CmdCheckColor.Deserialize(reader);
                    DumpToConsole(CheckColor, LogRPC);
                    break;

                case RpcCalls.CheckName:
                    var CheckName = CmdCheckName.Deserialize(reader);
                    DumpToConsole(CheckName, LogRPC);
                    break;

                case RpcCalls.CloseDoorsOfType:
                    var CloseDoorsOfType = RpcCloseDoorsOfType.Deserialize(reader);
                    DumpToConsole(CloseDoorsOfType, LogRPC);
                    break;

                case RpcCalls.EnterVent:
                    var EnterVent = RpcEnterVent.Deserialize(reader);
                    DumpToConsole(EnterVent, LogRPC);
                    break;

                case RpcCalls.ExitVent:
                    var ExitVent = RpcExitVent.Deserialize(reader);
                    DumpToConsole(ExitVent, LogRPC);
                    break;

                case RpcCalls.Exiled:
                    var exileid = reader.ReadPackedInt32();
                    Console.WriteLine("Exile id: " + exileid);
                    break;

                case RpcCalls.SendChat:
                    var chat = RpcSendChat.Deserialize(reader);
                    LogChatToConsole(RPC.targetNetId.ToString(), chat.text);
                    break;

                case RpcCalls.SendChatNote:
                    var chatnote = RpcSendChatNote.Deserialize(reader);
                    LogChatToConsole("server", "SendChatNote");
                    break;

                case RpcCalls.SetColor:
                    var SetColor = RpcSetColor.Deserialize(reader);
                    DumpToConsole(SetColor, LogRPC);
                    break;

                case RpcCalls.SetSkin:
                    var skin = RpcSetSkin.Deserialize(reader);
                    DumpToConsole(skin, LogRPC);
                    break;

                case RpcCalls.SetHat:
                    var hat = RpcSetHat.Deserialize(reader);
                    Console.WriteLine($"Set hat: [{(int)hat.hatId}]{hat.hatId}");
                    break;

                case RpcCalls.SetPet:
                    var setpet = RpcSetPet.Deserialize(reader);
                    DumpToConsole(setpet, LogRPC);
                    break;

                case RpcCalls.SetName:
                    var setname = RpcSetName.Deserialize(reader);
                    DumpToConsole(setname, LogRPC);
                    break;

                case RpcCalls.SetTasks:
                    var SetTasks = RpcSetTasks.Deserialize(reader);
                    DumpToConsole(SetTasks, LogRPC);
                    break;

                case RpcCalls.SetInfected:
                    var infected = RpcSetInfected.Deserialize(reader);
                    DumpToConsole(infected);
                    break;

                case RpcCalls.SetScanner:
                    var SetScanner = RpcSetScanner.Deserialize(reader);
                    DumpToConsole(SetScanner, LogRPC);
                    break;

                case RpcCalls.AddVote:
                    var addvote = RpcAddVote.Deserialize(reader);
                    DumpToConsole(addvote, LogRPC);
                    break;

                case RpcCalls.PlayAnimation:
                    var anim = RpcPlayAnimation.Deserialize(reader);
                    DumpToConsole(anim, LogRPC);
                    break;

                case RpcCalls.CastVote:
                    var castvote = CmdCastVote.Deserialize(reader);
                    DumpToConsole(castvote, LogRPC);
                    break;

                case RpcCalls.CompleteTask:
                    var complete = RpcCompleteTask.Deserialize(reader);
                    DumpToConsole(complete, LogRPC);
                    break;

                case RpcCalls.MurderPlayer:
                    var MurderPlayer = RpcMurderPlayer.Deserialize(reader);
                    var player       = EntityTracker.Get(MurderPlayer.netId);
                    DumpToConsole(MurderPlayer, LogRPC);
                    break;

                case RpcCalls.RepairSystem:
                    var RepairSystem = RpcRepairSystem.Deserialize(reader);
                    DumpToConsole(RepairSystem, LogRPC);
                    break;

                case RpcCalls.ReportDeadBody:
                    var ReportDeadBody = CmdReportDeadBody.Deserialize(reader);
                    DumpToConsole(ReportDeadBody, LogRPC);
                    break;

                case RpcCalls.SnapTo:
                    var SnapTo = RpcSnapTo.Deserialize(reader);
                    DumpToConsole(SnapTo, LogRPC);
                    break;

                case RpcCalls.StartMeeting:
                    var StartMeeting = RpcStartMeeting.Deserialize(reader);
                    DumpToConsole(StartMeeting, LogRPC);
                    break;

                case RpcCalls.VotingComplete:
                    var VotingComplete = RpcVotingComplete.Deserialize(reader);
                    DumpToConsole(VotingComplete, LogRPC);
                    break;

                case RpcCalls.SetStartCounter:
                    var startcounter = RpcSetStartCounter.Deserialize(reader);
                    DumpToConsole(startcounter, LogRPC);
                    break;

                case RpcCalls.SyncSettings:
                    var syncsettings = RpcSyncSettings.Deserialize(reader);
                    DumpToConsole(syncsettings, LogRPC);
                    break;

                //Dont have a message body
                case RpcCalls.Close:
                    break;

                //ComponentSpecific - it contains diffrent data depending on what component it's inteded for
                case RpcCalls.UpdateGameData:
                    var update = RpcUpdateGameData.Deserialize(reader);
                    DumpToConsole(update, LogRPC);
                    break;

                default:
                    Console.WriteLine($"Unhandled RPC command: " + RPC.callId);
                    break;
                }
                if (reader.GetBytesLeft() > 0 && LogNotConsumed)
                {
                    Console.WriteLine($"[{RPC.callId}]{reader.GetBytesLeft()} bytes not cunsumed");
                    reader.ReadBytesToEnd();
                }
                break;

            case GameDataType.Data:
                var            data = Data.Deserialize(reader);
                InnerNetObject entity;
                if (!EntityTracker.entities.TryGetValue(data.netId, out entity))
                {
                    Console.WriteLine($"Entity missing for id: {data.netId} size: {data.data.Length}");
                    return;
                }
                if (!(entity is CustomNetworkTransform))
                {
                    Console.WriteLine($"Recived Data for: {entity.GetType().Name} size: {data.data.Length}");
                }

                entity.Deserialize(new HazelBinaryReader(data.data), false);

                if (LogMoves && entity is CustomNetworkTransform move)
                {
                    Console.WriteLine($"[{dir}]Move command player: {move.OwnerId:0000} seq: {move.seq:0000} pos: {move.position} delta: {move.velocity}");
                }

                break;

            case GameDataType.Spawn:
                var spawn = Spawn.Deserialize(reader);
                Console.WriteLine("Spawning: " + spawn.spawnId);
                switch (spawn.spawnId)
                {
                case 0:
                    var shipStatus = new ShipStatus();
                    shipStatus.OwnerId = spawn.ownerId;
                    shipStatus.NetId   = spawn.children[0].netId;
                    shipStatus.Deserialize(new HazelBinaryReader(spawn.children[0].body), true);
                    EntityTracker.Add(shipStatus);
                    break;

                case 1:
                    var meeting = new MeetingHud();
                    meeting.OwnerId = spawn.ownerId;
                    meeting.NetId   = spawn.children[0].netId;
                    meeting.Deserialize(new HazelBinaryReader(spawn.children[0].body), true);
                    EntityTracker.Add(meeting);
                    break;

                case 2:
                    var lobby = new LobbyBehaviour();
                    lobby.OwnerId = spawn.ownerId;
                    lobby.NetId   = spawn.children[0].netId;
                    EntityTracker.Add(lobby);
                    break;

                case 3:
                    var gdc = new GameDataComponent();
                    gdc.OwnerId = spawn.ownerId;
                    gdc.NetId   = spawn.children[0].netId;
                    gdc.Deserialize(new HazelBinaryReader(spawn.children[0].body), true);
                    EntityTracker.Add(gdc);

                    var dummy2 = new DummyComponent();
                    dummy2.name    = "gamedata.dummy1";
                    dummy2.OwnerId = spawn.ownerId;
                    dummy2.NetId   = spawn.children[1].netId;
                    dummy2.Deserialize(new HazelBinaryReader(spawn.children[1].body), true);
                    EntityTracker.Add(dummy2);
                    break;

                case 4:        //player character
                    var player = new PlayerControl();
                    player.OwnerId = spawn.ownerId;
                    player.NetId   = spawn.children[0].netId;
                    player.Deserialize(new HazelBinaryReader(spawn.children[0].body), true);
                    EntityTracker.Add(player);

                    player.dummy1         = new DummyComponent();
                    player.dummy1.name    = "player.dummy1";
                    player.dummy1.OwnerId = spawn.ownerId;
                    player.dummy1.NetId   = spawn.children[1].netId;
                    player.dummy1.Deserialize(new HazelBinaryReader(spawn.children[1].body), true);
                    EntityTracker.Add(player.dummy1);

                    player.transform         = new CustomNetworkTransform();
                    player.transform.OwnerId = spawn.ownerId;
                    player.transform.NetId   = spawn.children[2].netId;
                    player.transform.Deserialize(new HazelBinaryReader(spawn.children[2].body), true);
                    EntityTracker.Add(player.transform);
                    DumpToConsole(player);
                    break;

                case 5:        //HeadQuarters
                    var hq = new ShipStatus();
                    hq.OwnerId = spawn.ownerId;
                    hq.NetId   = spawn.children[0].netId;
                    hq.Deserialize(new HazelBinaryReader(spawn.children[0].body), true);
                    EntityTracker.Add(hq);
                    break;

                case 6:        //PlanetMap
                    var polus = new ShipStatus();
                    polus.OwnerId = spawn.ownerId;
                    polus.NetId   = spawn.children[0].netId;
                    polus.Deserialize(new HazelBinaryReader(spawn.children[0].body), true);
                    EntityTracker.Add(polus);
                    break;

                case 7:        //AprilShipStatus
                default:
                    Console.WriteLine($"Unhandled spawnid: {spawn.spawnId}");
                    break;
                }
                break;

            case GameDataType.SceneChange:
                var scene = SceneChange.Deserialize(reader);
                if (scene.sceneName == "OnlineGame")
                {
                    //Starting game
                }
                DumpToConsole(scene);
                break;

            case GameDataType.Despawn:
                var despawn = Despawn.Deserialize(reader);
                EntityTracker.entities.Remove(despawn.netId);
                LogToConsole("Despawn Netid: " + despawn.netId);
                break;

            case GameDataType.Ready:
                var ready = Ready.Deserialize(reader);
                Console.WriteLine($"Ready: " + ready.playerId);
                break;

            case GameDataType.ChangeSettings:
                var changesettings = ChangeSettings.Deserialize(reader);
                DumpToConsole(changesettings);
                break;

            default:
                Console.WriteLine($"Unhandled Gamedatatype: {datatype}");
                break;
            }

            if (reader.GetBytesLeft() > 0 && LogNotConsumed)
            {
                Console.WriteLine($"[{datatype}]{reader.GetBytesLeft()} bytes not cunsumed");
                reader.ReadBytesToEnd();
            }
        }