Skip to content

Commit

Permalink
fix: player location not being sent to sockets
Browse files Browse the repository at this point in the history
Player location and data is now guaranteed too be sent to the sockets.

closes #21
  • Loading branch information
TGRHavoc committed May 17, 2019
1 parent f51e974 commit 0974a65
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 12 deletions.
27 changes: 27 additions & 0 deletions CHANGELOG.rst
Expand Up @@ -2,6 +2,33 @@ Changelog
=========


v2.2.4 (03-11-2017)
-------------------

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

Player location and data is now guaranteed too be sent to the sockets.
- Fixed linux post-build errors. [Jordan Dalton]

Fuck Visual Studio... I added the condition for a reason!
- Fixed async issues. [Jordan Dalton]

Ok. So, last update broke when multiple people connected because the writelock wasn't being re-set to 0. Hopefully this design keeps everything in sync and doesn't crash.

Update changelog

Other
~~~~~
- Merge pull request #20 from TGRHavoc/develop. [Jordan Dalton]

Fixed async issues
- Merge pull request #19 from TGRHavoc/develop. [Jordan Dalton]

v2.2.2


v2.2.3 (02-11-2017)
-------------------

Expand Down
4 changes: 1 addition & 3 deletions src/Live Map/Live Map.csproj
Expand Up @@ -81,9 +81,7 @@
</PostBuildEvent>
</PropertyGroup>
<PropertyGroup>
<PostBuildEvent>COPY /Y "$(TargetPath)" "F:\fx-server\resources\live_map\server"
COPY /Y "$(TargetDir)\deniszykov.WebSocketListener.dll" "F:\fx-server\resources\live_map"
COPY /Y "$(TargetDir)\Newtonsoft.Json.dll" "F:\fx-server\resources\live_map"
<PostBuildEvent>
</PostBuildEvent>
</PropertyGroup>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Expand Down
46 changes: 38 additions & 8 deletions src/Live Map/SocketHandler.cs
Expand Up @@ -39,7 +39,6 @@ class SocketHandler

ConcurrentQueue<JObject> sendQueue = new ConcurrentQueue<JObject>();


public SocketHandler(WebSocketServer server)
{
this.server = server;
Expand Down Expand Up @@ -127,9 +126,9 @@ public async Task SendWebsocketData()
// Only send the data every .5 seconds
await Task.Delay(TimeSpan.FromMilliseconds(LiveMap.waitSeconds)).ConfigureAwait(false);

//LiveMap.Log(LiveMap.LogLevel.All, "Checking send queue");
if (sendQueue.Count != 0)
{

JObject payload;
if (sendQueue.TryDequeue(out payload))
{
Expand All @@ -151,9 +150,41 @@ public async Task SendWebsocketData()
LiveMap.Log(LiveMap.LogLevel.Basic, "Couldn't get the latest payload to send.");
}

}else
}
else
{
//LiveMap.Log(LiveMap.LogLevel.All, "No payload to send... Waiting..");
// No payload in the queue, may as well send player data

// Generate the payload
JObject payload = new JObject();
JArray playerDataArray = new JArray();
lock (playerData)
{
foreach (KeyValuePair<string, JToken> data in playerData)
{
playerDataArray.Add(data.Value);
}
}

if (playerDataArray.Count == 0)
{
//LiveMap.Log(LiveMap.LogLevel.All, "playerDataArray.Count is 0");
continue;
}
payload["type"] = "playerData";
payload["payload"] = playerDataArray;

foreach (KeyValuePair<string, WebSocket> pair in clients)
{
string endpoint = pair.Key;
WebSocket ws = pair.Value;

//LiveMap.Log(LiveMap.LogLevel.All, "Sending payload of \"{0}\" to {1}", payload["type"], endpoint);

await ws.WriteStringAsync(payload.ToString(Newtonsoft.Json.Formatting.None)).ConfigureAwait(false);

}

}
}
}
Expand Down Expand Up @@ -200,7 +231,7 @@ public void AddPlayerData(string identifier, string key, object data)
if(playerObj[key] == null)
playerObj.Add(key, JToken.FromObject(data));

PlayerHadBeenUpdated(identifier, playerObj);
//PlayerHadBeenUpdated(identifier, playerObj);
}

LiveMap.Log(LiveMap.LogLevel.Basic, "Added \"{1}\" to player {0} with value of \"{2}\"", identifier, key, data);
Expand Down Expand Up @@ -235,7 +266,7 @@ public void UpdatePlayerData(string identifier, string key, object newData)
playerObj[key] = JToken.FromObject(newData);
playerData[identifier] = playerObj;

PlayerHadBeenUpdated(identifier, playerObj);
//PlayerHadBeenUpdated(identifier, playerObj);
}

LiveMap.Log(LiveMap.LogLevel.All, "Updated player {0}'s \"{1}\" to \"{2}\"", identifier, key, newData);
Expand Down Expand Up @@ -264,8 +295,7 @@ public void RemovePlayerData(string identifier, string key)
if (playerObj.Remove(key))
{
LiveMap.Log(LiveMap.LogLevel.Basic, "Removed \"{0}\" from player {1}", key, identifier);
PlayerHadBeenUpdated(identifier, playerObj);

//PlayerHadBeenUpdated(identifier, playerObj);
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion version.json
@@ -1,3 +1,3 @@
{
"resource" : "2.2.3"
"resource" : "2.2.4"
}

0 comments on commit 0974a65

Please sign in to comment.