renamed with nwn2ai prefix

This commit is contained in:
Crom (Thibaut CHARLES) 2015-04-17 21:36:14 +02:00
parent 4292f4b4de
commit 9a02c05f84
5 changed files with 34 additions and 20 deletions

View File

@ -17,7 +17,7 @@ using NWItemProperty = NWScript.NWScriptEngineStructure4;
namespace CLRScript namespace CLRScript
{ {
public partial class nwn2_ai_onmoduleload : CLRScriptBase, ICLRScriptImplementation public partial class nwn2ai_onmoduleload : CLRScriptBase, ICLRScriptImplementation
{ {
/// <summary> /// <summary>
@ -118,7 +118,7 @@ namespace CLRScript
/// <returns>The cloned script object is returned.</returns> /// <returns>The cloned script object is returned.</returns>
public IGeneratedScriptProgram CloneScriptProgram() public IGeneratedScriptProgram CloneScriptProgram()
{ {
return (IGeneratedScriptProgram)(new nwn2_ai_onmoduleload(this)); return (IGeneratedScriptProgram)(new nwn2ai_onmoduleload(this));
} }
/// <summary> /// <summary>

View File

@ -28,15 +28,15 @@ using System.Net.Sockets;
namespace CLRScript namespace CLRScript
{ {
public partial class nwn2_ai_onmoduleload : CLRScriptBase, ICLRScriptImplementation, IGeneratedScriptProgram public partial class nwn2ai_onmoduleload : CLRScriptBase, ICLRScriptImplementation, IGeneratedScriptProgram
{ {
public nwn2_ai_onmoduleload([In] NWScriptJITIntrinsics Intrinsics, [In] INWScriptProgram Host) public nwn2ai_onmoduleload([In] NWScriptJITIntrinsics Intrinsics, [In] INWScriptProgram Host)
{ {
InitScript(Intrinsics, Host); InitScript(Intrinsics, Host);
} }
private nwn2_ai_onmoduleload([In] nwn2_ai_onmoduleload Other) private nwn2ai_onmoduleload([In] nwn2ai_onmoduleload Other)
{ {
InitScript(Other); InitScript(Other);
@ -49,8 +49,14 @@ namespace CLRScript
// //
public static Type[] ScriptParameterTypes = { }; public static Type[] ScriptParameterTypes = { };
StreamWriter debugFile;
public Int32 ScriptMain([In] object[] ScriptParameters, [In] Int32 DefaultReturnCode) public Int32 ScriptMain([In] object[] ScriptParameters, [In] Int32 DefaultReturnCode)
{ {
debugFile = File.AppendText("nwnx4\\customlog.txt");
Debug("====================================> Start");
sockBufferIn = new Queue<string>(); sockBufferIn = new Queue<string>();
sockClients = new Dictionary<string,Socket>(); sockClients = new Dictionary<string,Socket>();
SocketConfigure(); SocketConfigure();
@ -77,33 +83,36 @@ namespace CLRScript
sockServer.Bind(iep); sockServer.Bind(iep);
sockServer.Listen(10); sockServer.Listen(10);
sockThread = new Thread(new ThreadStart(SockerHandler)); sockThread = new Thread(new ThreadStart(SocketHandler));
sockThread.Start(); sockThread.Start();
} }
void SockerHandler() void SocketHandler()
{ {
while(true){ while(true){
Socket sockClient = sockServer.Accept(); Debug("Accepting");
//Socket sockClient = sockServer.Accept();
sockServer.BeginAccept(new AsyncCallback(RequestHandler), sockServer); sockServer.BeginAccept(new AsyncCallback(RequestHandler), sockServer);
} }
} }
void RequestHandler(IAsyncResult state) void RequestHandler(IAsyncResult state)
{ {
Debug("Connection received");
//Socket listener = (Socket)state.AsyncState; //Socket listener = (Socket)state.AsyncState;
//Socket handler = listener.EndAccept(state); //Socket handler = listener.EndAccept(state);
Socket sockClient = sockServer.EndAccept(state); //Socket sockClient = sockServer.EndAccept(state);
//Debug("Connection Accepted");
byte[] rawLength = new byte[4]; //byte[] rawLength = new byte[4];
sockClient.Receive(rawLength); //sockClient.Receive(rawLength);
int length = rawLength[0]<<8 + rawLength[1]; //int length = rawLength[0]<<8 + rawLength[1];
byte[] rawData = new byte[length]; //byte[] rawData = new byte[length];
sockClient.Receive(rawData); //sockClient.Receive(rawData);
//string data = Encoding.UTF8.GetString(rawData);
string data = Encoding.UTF8.GetString(rawData); //Debug("got data: "+data);
sockBufferIn.Enqueue(data); //sockBufferIn.Enqueue(data);
} }
Socket sockServer; Socket sockServer;
@ -112,5 +121,10 @@ namespace CLRScript
//PNJ tag => Client socket //PNJ tag => Client socket
Dictionary<string, Socket> sockClients; Dictionary<string, Socket> sockClients;
private void Debug(string msg){
debugFile.WriteLine(DateTime.Now.ToLongTimeString()+": "+msg);
debugFile.Flush();
}
} }
} }

View File

@ -8,8 +8,8 @@
<ProjectGuid>{D2787600-DE01-4E09-9F74-1A13F1ADB4E8}</ProjectGuid> <ProjectGuid>{D2787600-DE01-4E09-9F74-1A13F1ADB4E8}</ProjectGuid>
<OutputType>Library</OutputType> <OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder> <AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>nwn2_ai_onmoduleload</RootNamespace> <RootNamespace>nwn2ai_onmoduleload</RootNamespace>
<AssemblyName>nwn2_ai_onmoduleload</AssemblyName> <AssemblyName>nwn2ai_onmoduleload</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion> <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment> <FileAlignment>512</FileAlignment>
<TargetFrameworkProfile /> <TargetFrameworkProfile />
@ -48,7 +48,7 @@
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="nwn2_ai_onmoduleload.cs" /> <Compile Include="nwn2ai_onmoduleload.cs" />
<Compile Include="..\CLRScriptSDK\NWScriptActions.cs" /> <Compile Include="..\CLRScriptSDK\NWScriptActions.cs" />
<Compile Include="..\CLRScriptSDK\NWScriptConstants.cs" /> <Compile Include="..\CLRScriptSDK\NWScriptConstants.cs" />
<Compile Include="..\CLRScriptSDK\NWScriptSupport.cs" /> <Compile Include="..\CLRScriptSDK\NWScriptSupport.cs" />