Skip to content

Commit

Permalink
feat: ability to add custom data to players
Browse files Browse the repository at this point in the history
Making it easier to add custom data to player such as their job. Also moved from the player name being the identifier.
  • Loading branch information
TGRHavoc committed May 17, 2019
1 parent d4613e6 commit 60af4ea
Showing 1 changed file with 36 additions and 6 deletions.
42 changes: 36 additions & 6 deletions src/Live Map/LiveMap.cs
Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -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;
}
Expand All @@ -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;
Expand Down

0 comments on commit 60af4ea

Please sign in to comment.