private void SocketObj_OnDataInvoke(BasePacket basePacket) { IGConsole.Instance.println(basePacket.packetType.ToString() + " Packet Received"); switch (basePacket.packetType) { case PacketType.CamFrame: CamPacket camPacket = (CamPacket)basePacket; Texture ttexture = camtexture.texture; camtexture.texture = TextureConverter.Base64ToTexture2D(camPacket.CamFrame); camtexture.gameObject.GetComponent <AspectRatioFitter>().aspectRatio = camtexture.texture.width / (float)camtexture.texture.height; if (ttexture != null) { Destroy(ttexture); } clientSender.SendPacket(new CamPacketRecived()); break; case PacketType.CamResolution: CamResolutionPacket crp = (CamResolutionPacket)basePacket; carStatusUIObj.CarDevice.camResolution = crp.Resolution; break; case PacketType.CarStatus: CarStatusPacket csp = (CarStatusPacket)basePacket; carStatusUIObj.CarDevice.SetStatus(csp.cardevice, csp.position, csp.rotation); clientSender.SendPacket(new CarStatusRecivedPacket()); break; case PacketType.CarGPSSpotStatus: CarGPSSpotStatusPacket cgpssp = (CarGPSSpotStatusPacket)basePacket; switch (cgpssp.GPSSpotManagerChangeType) { case GPSSpotManagerChangeType.AddSpot: carStatusUIObj.CarDevice.gPSSpotManager.AddPos(cgpssp.GPSPosition); carStatusUIObj.CarDevice.GPSSpotManagerUpdate(); break; case GPSSpotManagerChangeType.RemoveSpot: carStatusUIObj.CarDevice.gPSSpotManager.RemovePos(cgpssp.Index); carStatusUIObj.CarDevice.GPSSpotManagerUpdate(); break; case GPSSpotManagerChangeType.SetCurrentPos: carStatusUIObj.CarDevice.gPSSpotManager.CurrentMovePosIndex = cgpssp.Index; carStatusUIObj.CarDevice.GPSSpotManagerUpdate(); break; case GPSSpotManagerChangeType.OverWrite: carStatusUIObj.CarDevice.gPSSpotManager = cgpssp.GPSMover; break; default: break; } break; case PacketType.UpdateDataChanged: DataUpdatedPacket dup = (DataUpdatedPacket)basePacket; carStatusUIObj.CarDevice.modeType = dup.modeType; break; case PacketType.UpdateConsoleModeChanged: ConsoleUpdatedPacket cudp = (ConsoleUpdatedPacket)basePacket; switch (cudp.consoleMode) { case ConsoleMode.ViewBotList: ViewChanger.Instance.ChangeView(ViewChanger.ConsoleView.Botlist); break; case ConsoleMode.ViewSingleBot: ViewChanger.Instance.ChangeView(ViewChanger.ConsoleView.Console); break; default: break; } break; case PacketType.ClientsInfo: CoreLinker.GetComponent <CoreLinkerObj>().ClientsListController.RanderList(((ClientinfoPacket)basePacket).ClientsInfo); break; default: break; } }
public string GetPacketMembers(BasePacket basePacket) { StringBuilder PacketMembers = new StringBuilder("("); switch (basePacket.packetType) { case PacketType.ConnectionStat: ConnectionPacket cp = basePacket as ConnectionPacket; PacketMembers.Append("IsConnecting: "); PacketMembers.Append(cp.IsConnecting); PacketMembers.Append(", IsBot: "); PacketMembers.Append(cp.IsBot); PacketMembers.Append(", HasError: "); PacketMembers.Append(cp.HasError); break; case PacketType.CamFrame: CamPacket cap = basePacket as CamPacket; PacketMembers.Append("CamFrame: "); PacketMembers.Append(cap.CamFrame); break; case PacketType.CamConfig: CamConfigPacket cacc = basePacket as CamConfigPacket; PacketMembers.Append("camaraConfigType: "); PacketMembers.Append(cacc.camaraConfigType.ToString()); PacketMembers.Append(", enable: "); PacketMembers.Append(cacc.enable); break; case PacketType.CamResolutionReq: CamResolutionReqPacket crqr = basePacket as CamResolutionReqPacket; PacketMembers.Append("Resolution: "); PacketMembers.Append(crqr.Resolution); break; case PacketType.CamResolution: CamResolutionPacket crr = basePacket as CamResolutionPacket; PacketMembers.Append("Resolution: "); PacketMembers.Append(crr.Resolution); break; case PacketType.CamReceived: CamPacketRecived cpr = basePacket as CamPacketRecived; break; case PacketType.CarStatus: CarStatusPacket csp = basePacket as CarStatusPacket; PacketMembers.Append("cardevice: "); PacketMembers.Append(csp.cardevice); PacketMembers.Append(", position: "); PacketMembers.Append(csp.position); PacketMembers.Append(", rotation: "); PacketMembers.Append(csp.rotation); break; case PacketType.CarStatusReceived: CarStatusRecivedPacket csrp = basePacket as CarStatusRecivedPacket; break; case PacketType.CarGPSSpotStatus: CarGPSSpotStatusPacket cgpsssp = basePacket as CarGPSSpotStatusPacket; PacketMembers.Append("GPSMover: "); PacketMembers.Append(cgpsssp.GPSMover); PacketMembers.Append(", GPSPosition: "); PacketMembers.Append(cgpsssp.GPSPosition); PacketMembers.Append(", GPSSpotManagerChangeType: "); PacketMembers.Append(cgpsssp.GPSSpotManagerChangeType); PacketMembers.Append(", Index: "); PacketMembers.Append(cgpsssp.Index); break; case PacketType.CarStatusChangeReq: CarStatusChangeReqPacket cscrp = basePacket as CarStatusChangeReqPacket; PacketMembers.Append("ReqCarDevice: "); PacketMembers.Append(cscrp.ReqCarDevice); break; case PacketType.CarGPSSpotStatusChangeReq: CarGPSSpotStatusChangeReqPacket cgpssscrp = basePacket as CarGPSSpotStatusChangeReqPacket; PacketMembers.Append("GPSMover: "); PacketMembers.Append(cgpssscrp.GPSMover); PacketMembers.Append(", GPSPosition: "); PacketMembers.Append(cgpssscrp.GPSPosition); PacketMembers.Append(", GPSSpotManagerChangeType: "); PacketMembers.Append(cgpssscrp.GPSSpotManagerChangeType); PacketMembers.Append(", Index: "); PacketMembers.Append(cgpssscrp.Index); break; case PacketType.UpdateDataReq: DataUpdatePacket dup = basePacket as DataUpdatePacket; PacketMembers.Append("modeType: "); PacketMembers.Append(dup.modeType); break; case PacketType.UpdateDataChanged: DataUpdatedPacket dudp = basePacket as DataUpdatedPacket; PacketMembers.Append("modeType: "); PacketMembers.Append(dudp.modeType); break; case PacketType.UpdateConsoleModeReq: ConsoleUpdatePacket cup = basePacket as ConsoleUpdatePacket; PacketMembers.Append("consoleMode: "); PacketMembers.Append(cup.consoleMode); PacketMembers.Append("TargetBot: "); PacketMembers.Append(cup.TargetBot); break; case PacketType.UpdateConsoleModeChanged: ConsoleUpdatedPacket cudp = basePacket as ConsoleUpdatedPacket; PacketMembers.Append("consoleMode: "); PacketMembers.Append(cudp.consoleMode); break; case PacketType.UniversalCommand: UniversalCommandPacket ucp = basePacket as UniversalCommandPacket; PacketMembers.Append("key: "); PacketMembers.Append(ucp.key); PacketMembers.Append("keyType: "); PacketMembers.Append(ucp.keyType); break; case PacketType.ClientsInfoReq: ClientinfoReqPacket cirp = basePacket as ClientinfoReqPacket; break; case PacketType.ClientsInfo: ClientinfoPacket cip = basePacket as ClientinfoPacket; PacketMembers.Append("ClientsInfo: "); PacketMembers.Append(cip.ClientsInfo); break; default: break; } PacketMembers.Append(')'); return(PacketMembers.ToString()); }
public void IngestPacket(Packet p) { if (Initialized == false) //We have not set up the array of live driver data yet { if (p.PacketType == PacketType.Participants) //We wait for the participant packets to set up { ParticipantPacket pp = (ParticipantPacket)p; List <LiveDriverSessionData> NewData = new List <LiveDriverSessionData>(); for (int t = 0; t < pp.NumberOfActiveCars; t++) { LiveDriverSessionData ldsd = new LiveDriverSessionData(); ldsd.SelectedDriver = pp.FieldParticipantData[t].PilotingDriver; ldsd.TeamColor = CodemastersToolkit.GetTeamColorByTeam(pp.FieldParticipantData[t].ManufacturingTeam); ldsd.SelectedTeam = pp.FieldParticipantData[t].ManufacturingTeam; //The driver display name ldsd.DriverDisplayName = CodemastersToolkit.GetDriverDisplayNameFromDriver(pp.FieldParticipantData[t].PilotingDriver); //If the driver is not recognized (it is a real player, index 100, 101, 102, etc) this will return "Unknown" if (pp.FieldParticipantData[t].IsAiControlled == false) //If it is a player (the above most likely made the displat name 'Unknown', use the player name instead) { ldsd.DriverDisplayName = ApexVisualToolkit.CleanseString(pp.FieldParticipantData[t].Name); } NewData.Add(ldsd); } LiveDriverData = NewData.ToArray(); Initialized = true; } } else //We already have established a list of live driver session data { //If it is a lap packet, plug them in one by one if (p.PacketType == PacketType.Lap) { LapPacket lp = (LapPacket)p; for (int t = 0; t < LiveDriverData.Length; t++) { LiveDriverData[t].FeedLapData(lp.FieldLapData[t], lp.SessionTime); } //Supply the driver ahead distance for all cars (except first place) foreach (LiveDriverSessionData ldsd in LiveDriverData) { if (ldsd.Position != 1) //Only do this for cars that are NOT in first place { //Find the car that is directly ahead foreach (LapPacket.LapData ld in lp.FieldLapData) { if (ld.CarPosition == ldsd.Position - 1) //If it is the car ahead { ldsd.SetDriverAheadData(ld.TotalDistance); } } } } } else if (p.PacketType == PacketType.Session) //if it is a session packet, we have to plug the session type into each { SessionPacket sp = (SessionPacket)p; foreach (LiveDriverSessionData ldsd in LiveDriverData) { ldsd.SetSessionType(sp.SessionTypeMode); } } else if (p.PacketType == PacketType.CarStatus) { CarStatusPacket csp = (CarStatusPacket)p; for (int t = 0; t < LiveDriverData.Length; t++) { LiveDriverData[t].FeedCarStatusData(csp.FieldCarStatusData[t]); } } } }