public void ReadMonsterEnabled(NetBuffer inc) { InitMonstersEnabled(); List <string> monsterNames = MonsterEnabled.Keys.ToList(); foreach (string s in monsterNames) { MonsterEnabled[s] = inc.ReadBoolean(); } inc.ReadPadBits(); }
public void ServerRead(ClientNetObject type, NetBuffer msg, Client c) { bool active = msg.ReadBoolean(); item.CreateServerEvent(this); if (item.CanClientAccess(c)) { SetActive(active, c.Character); } }
public void ClientAdminRead(NetBuffer incMsg) { bool hasPermission = incMsg.ReadBoolean(); if (!hasPermission) { incMsg.ReadPadBits(); return; } bool isOwner = incMsg.ReadBoolean(); localEnabled = incMsg.ReadBoolean(); Enabled = localEnabled; incMsg.ReadPadBits(); whitelistedPlayers.Clear(); Int32 bannedPlayerCount = incMsg.ReadVariableInt32(); for (int i = 0; i < bannedPlayerCount; i++) { string name = incMsg.ReadString(); UInt16 uniqueIdentifier = incMsg.ReadUInt16(); string ip = ""; if (isOwner) { ip = incMsg.ReadString(); } else { ip = "IP concealed by host"; } whitelistedPlayers.Add(new WhiteListedPlayer(name, uniqueIdentifier, ip)); } if (whitelistFrame != null) { CreateWhiteListFrame(whitelistFrame.Parent); } }
public void ClientRead(ServerNetObject type, NetBuffer msg, float sendingTime) { if (correctionTimer > 0.0f) { StartDelayedCorrection(type, msg.ExtractBits(1 + 1 + 8 + 8 + 8 + 8), sendingTime); return; } AutoTemp = msg.ReadBoolean(); shutDown = msg.ReadBoolean(); Temperature = msg.ReadRangedSingle(0.0f, 100.0f, 8); targetFissionRate = msg.ReadRangedSingle(0.0f, 100.0f, 8); targetTurbineOutput = msg.ReadRangedSingle(0.0f, 100.0f, 8); degreeOfSuccess = msg.ReadRangedSingle(0.0f, 1.0f, 8); fissionRateScrollBar.BarScroll = targetFissionRate / 100.0f; turbineOutputScrollBar.BarScroll = targetTurbineOutput / 100.0f; onOffSwitch.BarScroll = shutDown ? Math.Max(onOffSwitch.BarScroll, 0.55f) : Math.Min(onOffSwitch.BarScroll, 0.45f); IsActive = true; }
public void Read(NetBuffer buffer) { DamageInfo.WeaponId = buffer.ReadInt32(); DamageInfo.AttackerEntityId = buffer.ReadInt32(); DamageInfo.VictimEntityId = buffer.ReadInt32(); DamageInfo.Amount = buffer.ReadInt32(); DamageInfo.ResultedInDeath = buffer.ReadBoolean(); DamageInfo.HitNormal = buffer.ReadVector3(); DamageInfo.HitPoint = buffer.ReadVector3(); DamageInfo.Viewpunch = buffer.ReadSingle(); DamageInfo.HitArea = (HitboxArea)buffer.ReadByte(); DamageInfo.DamageType = (DamageType)buffer.ReadByte(); }
public static PlayerInput Deserialize(NetBuffer reader) { var input = new PlayerInput { Timestamp = reader.ReadDouble(), Thrust = reader.ReadSingle(), Pitch = reader.ReadSingle(), Roll = reader.ReadSingle(), Yaw = reader.ReadSingle(), Boost = reader.ReadBoolean(), }; reader.SkipPadBits(7); return(input); }
private bool ReceiveSessionStateChanged(NetBuffer msg, NetworkMachine originMachine) { if (!originMachine.isHost) { return(false); } bool allowHostMigration, allowJoinInProgress; int maxGamers, privateGamerSlots; NetworkSessionState state; NetworkSessionProperties properties = new NetworkSessionProperties(); try { allowHostMigration = msg.ReadBoolean(); allowJoinInProgress = msg.ReadBoolean(); maxGamers = msg.ReadInt32(); privateGamerSlots = msg.ReadInt32(); state = (NetworkSessionState)msg.ReadByte(); if (!properties.Unpack(msg)) { return(false); } } catch { return(false); } this.allowHostMigration = allowHostMigration; this.allowJoinInProgress = allowJoinInProgress; this.maxGamers = maxGamers; this.privateGamerSlots = privateGamerSlots; this.state = state; this.properties.CopyValuesFrom(properties); return(true); }
public static PeerEndpoint ReadPeerEndpoint(this NetBuffer reader) { var hasInternalAddress = reader.ReadBoolean(); PeerEndpoint endpoint; if (hasInternalAddress) { endpoint = new PeerEndpoint(reader.ReadIpv4Endpoint(), reader.ReadIpv4Endpoint()); } else { endpoint = new PeerEndpoint(reader.ReadIpv4Endpoint()); } return(endpoint); }
public void ClientRead(ServerNetObject type, NetBuffer msg, float sendingTime) { for (int i = 0; i < customInterfaceElementList.Count; i++) { bool elementState = msg.ReadBoolean(); if (customInterfaceElementList[i].ContinuousSignal) { ((GUITickBox)uiElements[i]).Selected = elementState; TickBoxToggled(customInterfaceElementList[i], elementState); } else if (elementState) { ButtonClicked(customInterfaceElementList[i]); } } }
public void ClientRead(ServerNetObject type, NetBuffer msg, float sendingTime) { if (correctionTimer > 0.0f) { StartDelayedCorrection(type, msg.ExtractBits(16 + 1 + 15 + 8 + 8), sendingTime); return; } Temperature = msg.ReadRangedSingle(0.0f, 10000.0f, 16); AutoTemp = msg.ReadBoolean(); ShutDownTemp = msg.ReadRangedSingle(0.0f, 10000.0f, 15); CoolingRate = msg.ReadRangedSingle(0.0f, 100.0f, 8); FissionRate = msg.ReadRangedSingle(0.0f, 100.0f, 8); }
public void Read(NetBuffer buffer) { DataEntries.Clear(); Label = buffer.ReadString(); byte entryCount = buffer.ReadByte(); for (int i = 0; i < entryCount; i++) { var entry = new DataEntry(); entry.Type = (DataType)buffer.ReadByte(); switch (entry.Type) { case DataType.Bool: entry.BoolValue = buffer.ReadBoolean(); break; case DataType.Int: entry.IntValue = buffer.ReadInt32(); break; case DataType.Float: entry.FloatValue = buffer.ReadSingle(); break; case DataType.Byte: entry.ByteValue = buffer.ReadByte(); break; case DataType.String: entry.StringValue = buffer.ReadString(); break; case DataType.Vector3: entry.Vector3Value = buffer.ReadVector3(); break; case DataType.Bytes: var byteCount = buffer.ReadInt32(); entry.BytesValue = buffer.ReadBytes(byteCount); break; } DataEntries.Add(entry); } }
public static CBody ReadCBody(this NetBuffer message) { CBody retval = new CBody(); retval.Radius = message.ReadFloat(); retval.InvMass = message.ReadFloat(); retval.LinDrag = message.ReadFloat(); retval.Restitution = message.ReadFloat(); retval.SpeedMultiplier = message.ReadFloat(); retval.RotationMultiplier = message.ReadFloat(); retval.Velocity = message.ReadVector3(); retval.MaxVelocity = message.ReadFloat(); retval.EnableRot = message.ReadBoolean(); retval.Rot = message.ReadRotation(8); retval.RotAx = message.ReadVector3(); retval.RotVel = message.ReadFloat(); return(retval); }
protected void ReadReadyFlags(NetBuffer buffer) { List <Player> players = game.GetPlayers().list; int playersCount = buffer.ReadByte(); Debug.Assert(players.Count == playersCount); for (int i = 0; i < playersCount; ++i) { Player player = players[i]; bool isReady = buffer.ReadBoolean(); if (player.IsNetworkPlayer) { player.IsReady = isReady; } } }
private bool ReceiveGamerIdResponse(NetBuffer msg, NetworkMachine originMachine) { if (!originMachine.isHost) { return(false); } bool slotAvailable; byte id; try { slotAvailable = msg.ReadBoolean(); id = msg.ReadByte(); } catch { return(false); } if (slotAvailable && id == 255) { return(false); } if (pendingSignedInGamers.Count == 0) { // Don't treat as error but host will have marked slot used by client return(true); } if (!slotAvailable) { pendingSignedInGamers.RemoveAt(0); return(true); } var signedInGamer = pendingSignedInGamers[0]; pendingSignedInGamers.RemoveAt(0); var isPrivateSlot = isHost && GetOpenPrivateGamerSlots() > 0; var localGamer = new LocalNetworkGamer(signedInGamer, localMachine, id, isPrivateSlot); AddGamer(localGamer); SendGamerJoined(localGamer, null); return(true); }
public void ClientRead(NetBuffer incMsg) { ServerName = incMsg.ReadString(); ServerMessageText = incMsg.ReadString(); TickRate = incMsg.ReadRangedInteger(1, 60); GameMain.NetworkMember.TickRate = TickRate; ReadExtraCargo(incMsg); Voting.ClientRead(incMsg); bool isAdmin = incMsg.ReadBoolean(); incMsg.ReadPadBits(); if (isAdmin) { ClientAdminRead(incMsg); } }
private void ReadStatus(NetBuffer msg) { bool isDead = msg.ReadBoolean(); if (isDead) { CauseOfDeathType causeOfDeathType = (CauseOfDeathType)msg.ReadRangedInteger(0, Enum.GetValues(typeof(CauseOfDeathType)).Length - 1); AfflictionPrefab causeOfDeathAffliction = null; if (causeOfDeathType == CauseOfDeathType.Affliction) { int afflictionIndex = msg.ReadRangedInteger(0, AfflictionPrefab.List.Count - 1); causeOfDeathAffliction = AfflictionPrefab.List[afflictionIndex]; } byte severedLimbCount = msg.ReadByte(); if (!IsDead) { if (causeOfDeathType == CauseOfDeathType.Pressure) { Implode(true); } else { Kill(causeOfDeathType, causeOfDeathAffliction?.Instantiate(1.0f), true); } } for (int i = 0; i < severedLimbCount; i++) { int severedJointIndex = msg.ReadByte(); AnimController.SeverLimbJoint(AnimController.LimbJoints[severedJointIndex]); } } else { if (IsDead) { Revive(); } CharacterHealth.ClientRead(msg); } }
private static uint ReadUInt32Range(this NetBuffer buffer, int[] rangeBits) { int rangeMin = 0; for (int i = 0; i < rangeBits.Length; i++) { var rangeBit = rangeBits[i]; int rangeMax = rangeMin + ((1 << rangeBit) - 1); var isInRange = buffer.ReadBoolean(); if (isInRange) { return(buffer.ReadUInt32(rangeMin, rangeMax)); } rangeMin += (1 << rangeBit); } return(buffer.ReadUInt32( min: rangeMin, max: rangeMin + ((1 << rangeBits[rangeBits.Length - 1]) - 1))); }
public void ClientReadPosition(ServerNetObject type, NetBuffer msg, float sendingTime) { Vector2 newPosition = new Vector2(msg.ReadFloat(), msg.ReadFloat()); float newRotation = msg.ReadRangedSingle(0.0f, MathHelper.TwoPi, 7); bool awake = msg.ReadBoolean(); Vector2 newVelocity = Vector2.Zero; if (awake) { newVelocity = new Vector2( msg.ReadRangedSingle(-MaxVel, MaxVel, 12), msg.ReadRangedSingle(-MaxVel, MaxVel, 12)); } if (body == null) { DebugConsole.ThrowError("Received a position update for an item with no physics body (" + Name + ")"); return; } body.FarseerBody.Awake = awake; if (body.FarseerBody.Awake) { if ((newVelocity - body.LinearVelocity).Length() > 8.0f) { body.LinearVelocity = newVelocity; } } else { body.FarseerBody.Enabled = false; } if ((newPosition - SimPosition).Length() > body.LinearVelocity.Length() * 2.0f) { body.SetTransform(newPosition, newRotation); Vector2 displayPos = ConvertUnits.ToDisplayUnits(body.SimPosition); rect.X = (int)(displayPos.X - rect.Width / 2.0f); rect.Y = (int)(displayPos.Y + rect.Height / 2.0f); } }
public void ClientRead(ServerNetObject type, NetBuffer message, float sendingTime) { WaterVolume = message.ReadRangedSingle(0.0f, 1.5f, 8) * Volume; OxygenPercentage = message.ReadRangedSingle(0.0f, 100.0f, 8); bool hasFireSources = message.ReadBoolean(); int fireSourceCount = 0; if (hasFireSources) { fireSourceCount = message.ReadRangedInteger(0, 16); for (int i = 0; i < fireSourceCount; i++) { Vector2 pos = Vector2.Zero; float size = 0.0f; pos.X = MathHelper.Clamp(message.ReadRangedSingle(0.0f, 1.0f, 8), 0.05f, 0.95f); pos.Y = MathHelper.Clamp(message.ReadRangedSingle(0.0f, 1.0f, 8), 0.05f, 0.95f); size = message.ReadRangedSingle(0.0f, 1.0f, 8); pos = new Vector2( rect.X + rect.Width * pos.X, rect.Y - rect.Height + (rect.Height * pos.Y)); size = size * rect.Width; var newFire = i < fireSources.Count ? fireSources[i] : new FireSource(pos + Submarine.Position, null, true); newFire.Position = pos; newFire.Size = new Vector2(size, newFire.Size.Y); //ignore if the fire wasn't added to this room (invalid position)? if (!fireSources.Contains(newFire)) { newFire.Remove(); continue; } } } while (fireSources.Count > fireSourceCount) { fireSources[fireSources.Count - 1].Remove(); } }
public void ServerRead(ClientNetObject type, NetBuffer msg, Client c) { bool autoTemp = msg.ReadBoolean(); float shutDownTemp = msg.ReadRangedSingle(0.0f, 10000.0f, 15); float coolingRate = msg.ReadRangedSingle(0.0f, 100.0f, 8); float fissionRate = msg.ReadRangedSingle(0.0f, 100.0f, 8); if (!item.CanClientAccess(c)) { return; } if (!autoTemp && AutoTemp) { BlameOnBroken = c; } if (shutDownTemp > ShutDownTemp) { BlameOnBroken = c; } if (fissionRate > FissionRate) { BlameOnBroken = c; } AutoTemp = autoTemp; ShutDownTemp = shutDownTemp; CoolingRate = coolingRate; FissionRate = fissionRate; lastUser = c.Character; if (nextServerLogWriteTime == null) { nextServerLogWriteTime = Math.Max(lastServerLogWriteTime + 1.0f, (float)Timing.TotalTime); } //need to create a server event to notify all clients of the changed state unsentChanges = true; }
internal bool Unpack(NetBuffer msg) { int remoteCount; try { remoteCount = msg.ReadInt32(); } catch { return(false); } if (remoteCount != list.Count) { return(false); } var isSet = new bool[list.Count]; var value = new int[list.Count]; for (int i = 0; i < list.Count; i++) { try { isSet[i] = msg.ReadBoolean(); value[i] = msg.ReadInt32(); } catch { return(false); } } for (int i = 0; i < list.Count; i++) { list[i] = isSet[i] ? value[i] : (int?)null; } return(true); }
public override void ClientRead(ServerNetObject type, NetBuffer msg, float sendingTime) { base.ClientRead(type, msg, sendingTime); bool shouldBeAttached = msg.ReadBoolean(); Vector2 simPosition = new Vector2(msg.ReadFloat(), msg.ReadFloat()); if (!attachable) { DebugConsole.ThrowError("Received an attachment event for an item that's not attachable."); return; } if (shouldBeAttached) { if (!attached) { Drop(false, null); item.SetTransform(simPosition, 0.0f); AttachToWall(); } } else { if (attached) { DropConnectedWires(null); if (body != null) { item.body = body; item.body.Enabled = true; } IsActive = false; DeattachFromWall(); } } }
public void ClientRead(ServerNetObject type, NetBuffer msg, float sendingTime) { bool isAttached = msg.ReadBoolean(); if (isAttached) { item.Drop(); AttachToWall(); } else { DropConnectedWires(null); if (body != null) { item.body = body; item.body.Enabled = true; } IsActive = false; DeattachFromWall(); } }
private bool ReceiveGamerStateChanged(NetBuffer msg, NetworkMachine originMachine) { byte id; string displayName, gamertag; bool isReady; try { id = msg.ReadByte(); displayName = msg.ReadString(); gamertag = msg.ReadString(); isReady = msg.ReadBoolean(); } catch { return(false); } if (id == 255) { return(false); } if (!gamerFromId.ContainsKey(id)) { return(false); } var gamer = gamerFromId[id]; if (gamer.machine != originMachine) { return(false); } gamer.DisplayName = displayName; gamer.Gamertag = gamertag; gamer.isReady = isReady; return(true); }
public void ServerRead(ClientNetObject type, NetBuffer msg, Client c) { bool[] elementStates = new bool[customInterfaceElementList.Count]; for (int i = 0; i < customInterfaceElementList.Count; i++) { elementStates[i] = msg.ReadBoolean(); } CustomInterfaceElement clickedButton = null; if (item.CanClientAccess(c)) { for (int i = 0; i < customInterfaceElementList.Count; i++) { if (customInterfaceElementList[i].ContinuousSignal) { TickBoxToggled(customInterfaceElementList[i], elementStates[i]); } else if (elementStates[i]) { clickedButton = customInterfaceElementList[i]; ButtonClicked(customInterfaceElementList[i]); } } } //notify all clients of the new state GameMain.Server.CreateEntityEvent(item, new object[] { NetEntityEvent.Type.ComponentState, item.GetComponentIndex(this), clickedButton }); item.CreateServerEvent(this); }
public virtual void ClientRead(ServerNetObject type, NetBuffer msg, float sendingTime) { if (GameMain.Server != null) { return; } switch (type) { case ServerNetObject.ENTITY_POSITION: bool facingRight = AnimController.Dir > 0.0f; lastRecvPositionUpdateTime = (float)NetTime.Now; AnimController.Frozen = false; Enabled = true; UInt16 networkUpdateID = 0; if (msg.ReadBoolean()) { networkUpdateID = msg.ReadUInt16(); } else { bool aimInput = msg.ReadBoolean(); keys[(int)InputType.Aim].Held = aimInput; keys[(int)InputType.Aim].SetState(false, aimInput); bool useInput = msg.ReadBoolean(); keys[(int)InputType.Use].Held = useInput; keys[(int)InputType.Use].SetState(false, useInput); if (AnimController is HumanoidAnimController) { bool crouching = msg.ReadBoolean(); keys[(int)InputType.Crouch].Held = crouching; keys[(int)InputType.Crouch].SetState(false, crouching); AnimController.GrabLimb = (LimbType)msg.ReadByte(); } bool hasAttackLimb = msg.ReadBoolean(); if (hasAttackLimb) { bool attackInput = msg.ReadBoolean(); keys[(int)InputType.Attack].Held = attackInput; keys[(int)InputType.Attack].SetState(false, attackInput); } if (aimInput) { double aimAngle = ((double)msg.ReadUInt16() / 65535.0) * 2.0 * Math.PI; cursorPosition = (ViewTarget == null ? AnimController.AimSourcePos : ViewTarget.Position) + new Vector2((float)Math.Cos(aimAngle), (float)Math.Sin(aimAngle)) * 60.0f; TransformCursorPos(); } bool ragdollInput = msg.ReadBoolean(); keys[(int)InputType.Ragdoll].Held = ragdollInput; keys[(int)InputType.Ragdoll].SetState(false, ragdollInput); facingRight = msg.ReadBoolean(); } bool entitySelected = msg.ReadBoolean(); Entity selectedEntity = null; AnimController.Animation animation = AnimController.Animation.None; if (entitySelected) { ushort entityID = msg.ReadUInt16(); selectedEntity = FindEntityByID(entityID); if (selectedEntity is Character) { bool doingCpr = msg.ReadBoolean(); if (doingCpr && SelectedCharacter != null) { animation = AnimController.Animation.CPR; } } } Vector2 pos = new Vector2( msg.ReadFloat(), msg.ReadFloat()); float rotation = msg.ReadFloat(); ReadStatus(msg); msg.ReadPadBits(); int index = 0; if (GameMain.NetworkMember.Character == this) { var posInfo = new CharacterStateInfo(pos, rotation, networkUpdateID, facingRight ? Direction.Right : Direction.Left, selectedEntity, animation); while (index < memState.Count && NetIdUtils.IdMoreRecent(posInfo.ID, memState[index].ID)) { index++; } memState.Insert(index, posInfo); } else { var posInfo = new CharacterStateInfo(pos, rotation, sendingTime, facingRight ? Direction.Right : Direction.Left, selectedEntity, animation); while (index < memState.Count && posInfo.Timestamp > memState[index].Timestamp) { index++; } memState.Insert(index, posInfo); } break; case ServerNetObject.ENTITY_EVENT: int eventType = msg.ReadRangedInteger(0, 2); switch (eventType) { case 0: inventory.ClientRead(type, msg, sendingTime); break; case 1: byte ownerID = msg.ReadByte(); ResetNetState(); if (ownerID == GameMain.Client.ID) { if (controlled != null) { LastNetworkUpdateID = controlled.LastNetworkUpdateID; } controlled = this; IsRemotePlayer = false; GameMain.Client.Character = this; GameMain.LightManager.LosEnabled = true; } else if (controlled == this) { controlled = null; IsRemotePlayer = ownerID > 0; } break; case 2: ReadStatus(msg); break; } msg.ReadPadBits(); break; } }
private void ReadStatus(NetBuffer msg) { bool isDead = msg.ReadBoolean(); if (isDead) { causeOfDeath = (CauseOfDeath)msg.ReadByte(); byte severedLimbCount = msg.ReadByte(); if (!IsDead) { if (causeOfDeath == CauseOfDeath.Pressure) { Implode(true); } else { Kill(causeOfDeath, true); } } for (int i = 0; i < severedLimbCount; i++) { int severedJointIndex = msg.ReadByte(); AnimController.SeverLimbJoint(AnimController.LimbJoints[severedJointIndex]); } } else { this.isDead = false; health = msg.ReadRangedSingle(minHealth, maxHealth, 8); bool lowOxygen = msg.ReadBoolean(); if (lowOxygen) { Oxygen = msg.ReadRangedSingle(-100.0f, 100.0f, 8); } else { Oxygen = 100.0f; } bool isBleeding = msg.ReadBoolean(); if (isBleeding) { bleeding = msg.ReadRangedSingle(0.0f, 5.0f, 8); } else { bleeding = 0.0f; } bool stunned = msg.ReadBoolean(); if (stunned) { float newStunTimer = msg.ReadRangedSingle(0.0f, 60.0f, 8); SetStun(newStunTimer, true, true); } else { SetStun(0.0f, true, true); } bool ragdolled = msg.ReadBoolean(); IsRagdolled = ragdolled; bool huskInfected = msg.ReadBoolean(); if (huskInfected) { HuskInfectionState = Math.Max(HuskInfectionState, 0.01f); } else { HuskInfectionState = 0.0f; } } }
public static Character ReadSpawnData(NetBuffer inc, bool spawn = true) { DebugConsole.NewMessage("READING CHARACTER SPAWN DATA", Color.Cyan); if (GameMain.Server != null) { return(null); } bool noInfo = inc.ReadBoolean(); ushort id = inc.ReadUInt16(); string configPath = inc.ReadString(); Vector2 position = new Vector2(inc.ReadFloat(), inc.ReadFloat()); bool enabled = inc.ReadBoolean(); DebugConsole.Log("Received spawn data for " + configPath); Character character = null; if (noInfo) { if (!spawn) { return(null); } character = Character.Create(configPath, position, null, true); character.ID = id; } else { bool hasOwner = inc.ReadBoolean(); int ownerId = hasOwner ? inc.ReadByte() : -1; string newName = inc.ReadString(); byte teamID = inc.ReadByte(); bool hasAi = inc.ReadBoolean(); bool isFemale = inc.ReadBoolean(); int headSpriteID = inc.ReadByte(); string jobName = inc.ReadString(); JobPrefab jobPrefab = null; Dictionary <string, int> skillLevels = new Dictionary <string, int>(); if (!string.IsNullOrEmpty(jobName)) { jobPrefab = JobPrefab.List.Find(jp => jp.Name == jobName); int skillCount = inc.ReadByte(); for (int i = 0; i < skillCount; i++) { string skillName = inc.ReadString(); int skillLevel = inc.ReadRangedInteger(0, 100); skillLevels.Add(skillName, skillLevel); } } if (!spawn) { return(null); } CharacterInfo ch = new CharacterInfo(configPath, newName, isFemale ? Gender.Female : Gender.Male, jobPrefab); ch.HeadSpriteId = headSpriteID; System.Diagnostics.Debug.Assert(skillLevels.Count == ch.Job.Skills.Count); if (ch.Job != null) { foreach (KeyValuePair <string, int> skill in skillLevels) { Skill matchingSkill = ch.Job.Skills.Find(s => s.Name == skill.Key); if (matchingSkill == null) { DebugConsole.ThrowError("Skill \"" + skill.Key + "\" not found in character \"" + newName + "\""); continue; } matchingSkill.Level = skill.Value; } } character = Create(configPath, position, ch, GameMain.Client.ID != ownerId, hasAi); character.ID = id; character.TeamID = teamID; if (GameMain.Client.ID == ownerId) { GameMain.Client.Character = character; Controlled = character; GameMain.LightManager.LosEnabled = true; character.memInput.Clear(); character.memState.Clear(); character.memLocalState.Clear(); } else { var ownerClient = GameMain.Client.ConnectedClients.Find(c => c.ID == ownerId); if (ownerClient != null) { ownerClient.Character = character; } } if (configPath == Character.HumanConfigFile) { GameMain.GameSession.CrewManager.AddCharacter(character); } } character.Enabled = Controlled == character || enabled; return(character); }
//static because we may need to instantiate the campaign if it hasn't been done yet public static void ClientRead(NetBuffer msg) { byte campaignID = msg.ReadByte(); UInt16 updateID = msg.ReadUInt16(); UInt16 saveID = msg.ReadUInt16(); string mapSeed = msg.ReadString(); UInt16 currentLocIndex = msg.ReadUInt16(); UInt16 selectedLocIndex = msg.ReadUInt16(); byte selectedMissionIndex = msg.ReadByte(); UInt16 startWatchmanID = msg.ReadUInt16(); UInt16 endWatchmanID = msg.ReadUInt16(); int money = msg.ReadInt32(); bool purchasedHullRepairs = msg.ReadBoolean(); bool purchasedItemRepairs = msg.ReadBoolean(); UInt16 purchasedItemCount = msg.ReadUInt16(); List <PurchasedItem> purchasedItems = new List <PurchasedItem>(); for (int i = 0; i < purchasedItemCount; i++) { UInt16 itemPrefabIndex = msg.ReadUInt16(); UInt16 itemQuantity = msg.ReadUInt16(); purchasedItems.Add(new PurchasedItem(MapEntityPrefab.List[itemPrefabIndex] as ItemPrefab, itemQuantity)); } bool hasCharacterData = msg.ReadBoolean(); CharacterInfo myCharacterInfo = null; if (hasCharacterData) { myCharacterInfo = CharacterInfo.ClientRead(Character.HumanConfigFile, msg); } MultiPlayerCampaign campaign = GameMain.GameSession?.GameMode as MultiPlayerCampaign; if (campaign == null || campaignID != campaign.CampaignID) { string savePath = SaveUtil.CreateSavePath(SaveUtil.SaveType.Multiplayer); GameMain.GameSession = new GameSession(null, savePath, GameModePreset.List.Find(g => g.Identifier == "multiplayercampaign")); campaign = ((MultiPlayerCampaign)GameMain.GameSession.GameMode); campaign.CampaignID = campaignID; campaign.GenerateMap(mapSeed); GameMain.NetLobbyScreen.ToggleCampaignMode(true); } //server has a newer save file if (NetIdUtils.IdMoreRecent(saveID, campaign.PendingSaveID)) { /*//stop any active campaign save transfers, they're outdated now * List<FileReceiver.FileTransferIn> saveTransfers = * GameMain.Client.FileReceiver.ActiveTransfers.FindAll(t => t.FileType == FileTransferType.CampaignSave); * * foreach (var transfer in saveTransfers) * { * GameMain.Client.FileReceiver.StopTransfer(transfer); * } * * GameMain.Client.RequestFile(FileTransferType.CampaignSave, null, null);*/ campaign.PendingSaveID = saveID; } if (NetIdUtils.IdMoreRecent(updateID, campaign.lastUpdateID)) { campaign.Map.SetLocation(currentLocIndex == UInt16.MaxValue ? -1 : currentLocIndex); campaign.Map.SelectLocation(selectedLocIndex == UInt16.MaxValue ? -1 : selectedLocIndex); campaign.Map.SelectMission(selectedMissionIndex); campaign.startWatchmanID = startWatchmanID; campaign.endWatchmanID = endWatchmanID; campaign.Money = money; campaign.PurchasedHullRepairs = purchasedHullRepairs; campaign.PurchasedItemRepairs = purchasedItemRepairs; campaign.CargoManager.SetPurchasedItems(purchasedItems); if (myCharacterInfo != null) { GameMain.Client.CharacterInfo = myCharacterInfo; GameMain.NetLobbyScreen.SetCampaignCharacterInfo(myCharacterInfo); } else { GameMain.NetLobbyScreen.SetCampaignCharacterInfo(null); } campaign.lastUpdateID = updateID; } }
public void ClientRead(ServerNetObject type, NetBuffer msg, float sendingTime) { SetActive(msg.ReadBoolean()); progressTimer = msg.ReadSingle(); }