From 60af4ea2f60195f4b5fe0340e4f09192903e67d2 Mon Sep 17 00:00:00 2001 From: Jordan Dalton Date: Tue, 23 May 2017 06:38:51 +0100 Subject: [PATCH] feat: ability to add custom data to players Making it easier to add custom data to player such as their job. Also moved from the player name being the identifier. --- src/Live Map/LiveMap.cs | 42 +++++++++++++++++++++++++++++++++++------ 1 file changed, 36 insertions(+), 6 deletions(-) diff --git a/src/Live Map/LiveMap.cs b/src/Live Map/LiveMap.cs index 0c75eeb..4051418 100644 --- a/src/Live Map/LiveMap.cs +++ b/src/Live Map/LiveMap.cs @@ -125,14 +125,14 @@ public void stop() wssv.Stop(); } - public void addPlayer(string name, float x = 0f, float y = 0f, float z = 0f) + public void addPlayer(string identifier, string name, float x = 0f, float y = 0f, float z = 0f) { lock (playerLocations) { bool updatedPlayer = false; foreach (var item in playerLocations) { - if (item["name"].ToString() == name) + if (item["id"].ToString() == identifier) { // Update it item["x"] = x; @@ -151,6 +151,7 @@ public void addPlayer(string name, float x = 0f, float y = 0f, float z = 0f) { // Add them JObject playerObj = new JObject(); + playerObj.Add("id", identifier); playerObj.Add("name", name); playerObj.Add("x", x); playerObj.Add("y", y); @@ -160,15 +161,43 @@ public void addPlayer(string name, float x = 0f, float y = 0f, float z = 0f) } } } + public void addPlayerString(string id, string key, string data) + { + lock (playerLocations) + { + foreach (var item in playerLocations) + { + if (item["id"].ToString() == id) + { + // Update it + item[key] = data; + } + } + } + } + public void addPlayerFloat(string id, string key, float data) + { + lock (playerLocations) + { + foreach (var item in playerLocations) + { + if (item["id"].ToString() == id) + { + // Update it + item[key] = data; + } + } + } + } - public void removePlayer(string name) + public void removePlayer(string identifier) { lock (playerLocations) { JToken token = null; foreach (var item in playerLocations) { - if (item["name"].ToString() == name) + if (item["id"].ToString() == identifier) { token = item; } @@ -181,16 +210,17 @@ public void removePlayer(string name) JObject obj = new JObject(); obj["type"] = "playerLeft"; - obj["payload"] = name; + obj["payload"] = identifier; wssv.WebSocketServices["/"].Sessions.Broadcast(obj.ToString(Newtonsoft.Json.Formatting.None)); } - public void addBlip(string name, string type = "waypoint", float x = 0f, float y = 0f, float z = 0f) + public void addBlip(string name, string desc="", string type = "waypoint", float x = 0f, float y = 0f, float z = 0f) { JObject blip = new JObject(); blip["name"] = name; + blip["description"] = desc; blip["type"] = type; blip["x"] = x; blip["y"] = y;