Json parsing

This commit is contained in:
Crom (Thibaut CHARLES) 2015-04-21 23:45:52 +02:00
parent 20fbc943ce
commit 25163296c5
2 changed files with 25 additions and 2 deletions

View File

@ -25,6 +25,7 @@ using System.Threading;
using System.IO;
using System.Net;
using System.Net.Sockets;
using Newtonsoft.Json;
namespace CLRScript
{
@ -69,10 +70,29 @@ namespace CLRScript
public void Heartbeat()
{
ActionSpeakString("hb", TALKVOLUME_TALK);
ActionSpeakString("hb", TALKVOLUME_SHOUT);
DelayCommand(0.5f, Heartbeat);
//Process queued requests
Debug("Proc cmds");
while(sockBufferIn.Count>0){
Tuple<string, Socket> req = sockBufferIn.Dequeue();
var json = JsonConvert.DeserializeObject<dynamic>(req.Item1);
switch ((string)json.action) {
case "bind": {
Debug("Bind request to '"+json.target+"'");
if (!sockClients.ContainsKey(json.target)) {
sockClients.Add(json.target, req.Item2);
//Reply ok
}
else {
//Reply Already binded
}
}break;
}
}
}
@ -99,7 +119,7 @@ namespace CLRScript
sockClient.Receive(rawData, rawData.Length, 0);
string data = Encoding.UTF8.GetString(rawData);
Debug("Queued "+data);
//Debug("Queued "+data);
sockBufferIn.Enqueue(new Tuple<string,Socket>(data, sockClient));
}
else

View File

@ -32,6 +32,9 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<EmbedInteropTypes>False</EmbedInteropTypes>
</Reference>
<Reference Include="NWNScriptJITIntrinsics, Version=1.0.0.1, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\CLRScriptSDK\NWNScriptJITIntrinsics.dll</HintPath>
</Reference>