Json parsing
This commit is contained in:
parent
20fbc943ce
commit
25163296c5
@ -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
|
||||
|
@ -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>
|
||||
|
Loading…
Reference in New Issue
Block a user