From 11f2bf4b38f2fba7269d5fe4cd070570d1303803 Mon Sep 17 00:00:00 2001 From: Joonas Rikkonen Date: Mon, 1 Apr 2019 14:27:11 +0300 Subject: [PATCH] (f152bbbe1) Servers includes skill identifiers in CharacterInfo data sent to clients. Sending only the levels and assuming the client has the same skills in the same order made it difficult for servers to modify the skills without client-side modifications. Closes #1335 --- .../Source/Characters/CharacterInfo.cs | 10 ++++++---- .../Source/Characters/CharacterInfo.cs | 2 ++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/Barotrauma/BarotraumaClient/Source/Characters/CharacterInfo.cs b/Barotrauma/BarotraumaClient/Source/Characters/CharacterInfo.cs index a4eb436a9..e01a3dd2b 100644 --- a/Barotrauma/BarotraumaClient/Source/Characters/CharacterInfo.cs +++ b/Barotrauma/BarotraumaClient/Source/Characters/CharacterInfo.cs @@ -241,10 +241,12 @@ namespace Barotrauma if (!string.IsNullOrEmpty(jobIdentifier)) { jobPrefab = JobPrefab.List.Find(jp => jp.Identifier == jobIdentifier); - for (int i = 0; i < jobPrefab.Skills.Count; i++) + byte skillCount = inc.ReadByte(); + for (int i = 0; i < skillCount; i++) { + string skillIdentifier = inc.ReadString(); float skillLevel = inc.ReadSingle(); - skillLevels.Add(jobPrefab.Skills[i].Identifier, skillLevel); + skillLevels.Add(skillIdentifier, skillLevel); } } @@ -254,7 +256,6 @@ namespace Barotrauma ID = infoID, }; ch.RecreateHead(headSpriteID,(Race)race, (Gender)gender, hairIndex, beardIndex, moustacheIndex, faceAttachmentIndex); - System.Diagnostics.Debug.Assert(skillLevels.Count == ch.Job.Skills.Count); if (ch.Job != null) { foreach (KeyValuePair skill in skillLevels) @@ -262,11 +263,12 @@ namespace Barotrauma Skill matchingSkill = ch.Job.Skills.Find(s => s.Identifier == skill.Key); if (matchingSkill == null) { - DebugConsole.ThrowError("Skill \"" + skill.Key + "\" not found in character \"" + newName + "\""); + ch.Job.Skills.Add(new Skill(skill.Key, skill.Value)); continue; } matchingSkill.Level = skill.Value; } + ch.Job.Skills.RemoveAll(s => !skillLevels.ContainsKey(s.Identifier)); } return ch; } diff --git a/Barotrauma/BarotraumaServer/Source/Characters/CharacterInfo.cs b/Barotrauma/BarotraumaServer/Source/Characters/CharacterInfo.cs index 29f5bade5..8a75d42e0 100644 --- a/Barotrauma/BarotraumaServer/Source/Characters/CharacterInfo.cs +++ b/Barotrauma/BarotraumaServer/Source/Characters/CharacterInfo.cs @@ -20,8 +20,10 @@ namespace Barotrauma if (Job != null) { msg.Write(Job.Prefab.Identifier); + msg.Write((byte)Job.Skills.Count); foreach (Skill skill in Job.Skills) { + msg.Write(skill.Identifier); msg.Write(skill.Level); } }