Skip to content

Commit

Permalink
fix: add null checks to various API functions
Browse files Browse the repository at this point in the history
Moved where the null checks are in the internal functions. This makes sure that the `MakeSurePlayerExists` doesn't get passed a null value.

closes #24
  • Loading branch information
TGRHavoc committed May 17, 2019
1 parent 461e92c commit bbfc23b
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 10 deletions.
38 changes: 38 additions & 0 deletions CHANGELOG.rst
Expand Up @@ -2,8 +2,46 @@ Changelog
=========


v2.2.9 (26-11-2017)
-------------------

Fix
~~~
- Fixed #24. [Jordan Dalton]

Moved where the null checks are in the internal functions. This makes sure that the `MakeSurePlayerExists` doesn't get passed a null value.


v2.2.8 (24-11-2017)
-------------------

Changes
~~~~~~~
- Update to v2.2.8. [Jordan Dalton]

Thanks to glitch for pointing out my spelling mistakes (hence the "Fixed small mistake" and "Shhh." commits).
- Update where access-control is being written. [Jordan Dalton]

Before, the access-control-origin was only being written when sending the blips, this fixes that so, the iterface can see any errors.

Fix
~~~
- Fixed small mistake. [Jordan Dalton]

Other
~~~~~
- Shhh. [Jordan Dalton]


v2.2.7 (22-11-2017)
-------------------

Changes
~~~~~~~
- Update to v2.2.7. [Jordan Dalton]

Other
~~~~~
- Possibly fixed "Too many files open" error. [Jordan Dalton]


Expand Down
6 changes: 3 additions & 3 deletions server/blips_server.lua
Expand Up @@ -119,9 +119,6 @@ end
@param res The result object that can be sent data
]]
function sendBlips(res)
-- Restrict the origin if set, otherwise allow everyone
res.writeHead(200, { ["Access-Control-Allow-Origin"] = GetConvar("livemap_access_control", "*")} )

if not blipsIsEmpty() then
res.send(json.encode(blips))
else
Expand Down Expand Up @@ -389,6 +386,9 @@ end, true)
SetHttpHandler(function(req, res)
local path = req.path

-- Restrict the origin if set, otherwise allow everyone
res.writeHead(200, { ["Access-Control-Allow-Origin"] = GetConvar("livemap_access_control", "*")} )

if path == "/blips" or path == "/blips.json" then
return sendBlips(res)
end
Expand Down
11 changes: 5 additions & 6 deletions src/Live Map/SocketHandler.cs
Expand Up @@ -210,9 +210,6 @@ public async Task SendWebsocketData()

public void AddPlayerData(string identifier, string key, object data)
{
LiveMap.Log(LiveMap.LogLevel.All, "Adding player {0}'s \"{1}\"", identifier, key);
MakeSurePlayerExists(identifier);

if (string.IsNullOrEmpty(identifier))
{
LiveMap.Log(LiveMap.LogLevel.Basic, "Identifier is null or empty");
Expand All @@ -230,6 +227,9 @@ public void AddPlayerData(string identifier, string key, object data)
return;
}

LiveMap.Log(LiveMap.LogLevel.All, "Adding player {0}'s \"{1}\"", identifier, key);
MakeSurePlayerExists(identifier);

lock (playerData)
{
JObject playerObj = (JObject)playerData[identifier];
Expand All @@ -245,9 +245,6 @@ public void AddPlayerData(string identifier, string key, object data)

public void UpdatePlayerData(string identifier, string key, object newData)
{
LiveMap.Log(LiveMap.LogLevel.All, "Updating player {0}'s \"{1}\"", identifier, key);
MakeSurePlayerExists(identifier);

if (string.IsNullOrEmpty(identifier))
{
LiveMap.Log(LiveMap.LogLevel.Basic, "Identifier is null or empty. Cannot update player data");
Expand All @@ -265,6 +262,8 @@ public void UpdatePlayerData(string identifier, string key, object newData)
LiveMap.Log(LiveMap.LogLevel.Basic, "Cannot update \"{0}\" for {1} because it's null", key, identifier);
return;
}
LiveMap.Log(LiveMap.LogLevel.All, "Updating player {0}'s \"{1}\"", identifier, key);
MakeSurePlayerExists(identifier);

lock (playerData)
{
Expand Down
2 changes: 1 addition & 1 deletion version.json
@@ -1,3 +1,3 @@
{
"resource" : "2.2.7"
"resource" : "2.2.9"
}

0 comments on commit bbfc23b

Please sign in to comment.