482 lines
16 KiB
C#
482 lines
16 KiB
C#
#if USE_UNI_LUA
|
|
using LuaAPI = UniLua.Lua;
|
|
using RealStatePtr = UniLua.ILuaState;
|
|
using LuaCSFunction = UniLua.CSharpFunctionDelegate;
|
|
#else
|
|
using LuaAPI = XLua.LuaDLL.Lua;
|
|
using RealStatePtr = System.IntPtr;
|
|
using LuaCSFunction = XLua.LuaDLL.lua_CSFunction;
|
|
#endif
|
|
|
|
using XLua;
|
|
using System.Collections.Generic;
|
|
|
|
|
|
namespace XLua.CSObjectWrap
|
|
{
|
|
using Utils = XLua.Utils;
|
|
public class BFNetClientWrap
|
|
{
|
|
public static void __Register(RealStatePtr L)
|
|
{
|
|
ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);
|
|
System.Type type = typeof(BF.NetClient);
|
|
Utils.BeginObjectRegister(type, L, translator, 0, 13, 0, 0);
|
|
|
|
Utils.RegisterFunc(L, Utils.METHOD_IDX, "Init", _m_Init);
|
|
Utils.RegisterFunc(L, Utils.METHOD_IDX, "Start", _m_Start);
|
|
Utils.RegisterFunc(L, Utils.METHOD_IDX, "Shutdown", _m_Shutdown);
|
|
Utils.RegisterFunc(L, Utils.METHOD_IDX, "SetupService", _m_SetupService);
|
|
Utils.RegisterFunc(L, Utils.METHOD_IDX, "Connect", _m_Connect);
|
|
Utils.RegisterFunc(L, Utils.METHOD_IDX, "Reconnect", _m_Reconnect);
|
|
Utils.RegisterFunc(L, Utils.METHOD_IDX, "Close", _m_Close);
|
|
Utils.RegisterFunc(L, Utils.METHOD_IDX, "Send", _m_Send);
|
|
Utils.RegisterFunc(L, Utils.METHOD_IDX, "ReadMessage", _m_ReadMessage);
|
|
Utils.RegisterFunc(L, Utils.METHOD_IDX, "RecycleMessage", _m_RecycleMessage);
|
|
Utils.RegisterFunc(L, Utils.METHOD_IDX, "GetConnectStatus", _m_GetConnectStatus);
|
|
Utils.RegisterFunc(L, Utils.METHOD_IDX, "GetConnectIP", _m_GetConnectIP);
|
|
Utils.RegisterFunc(L, Utils.METHOD_IDX, "GetServerTimestamp", _m_GetServerTimestamp);
|
|
|
|
|
|
|
|
|
|
|
|
Utils.EndObjectRegister(type, L, translator, null, null,
|
|
null, null, null);
|
|
|
|
Utils.BeginClassRegister(type, L, __CreateInstance, 1, 1, 0);
|
|
|
|
|
|
|
|
Utils.RegisterFunc(L, Utils.CLS_GETTER_IDX, "Instance", _g_get_Instance);
|
|
|
|
|
|
|
|
Utils.EndClassRegister(type, L, translator);
|
|
}
|
|
|
|
[MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))]
|
|
static int __CreateInstance(RealStatePtr L)
|
|
{
|
|
return LuaAPI.luaL_error(L, "BF.NetClient does not have a constructor!");
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))]
|
|
static int _m_Init(RealStatePtr L)
|
|
{
|
|
try {
|
|
|
|
ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);
|
|
|
|
|
|
BF.NetClient gen_to_be_invoked = (BF.NetClient)translator.FastGetCSObj(L, 1);
|
|
|
|
|
|
|
|
{
|
|
|
|
gen_to_be_invoked.Init( );
|
|
|
|
|
|
|
|
return 0;
|
|
}
|
|
|
|
} catch(System.Exception gen_e) {
|
|
return LuaAPI.luaL_error(L, "c# exception:" + gen_e);
|
|
}
|
|
|
|
}
|
|
|
|
[MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))]
|
|
static int _m_Start(RealStatePtr L)
|
|
{
|
|
try {
|
|
|
|
ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);
|
|
|
|
|
|
BF.NetClient gen_to_be_invoked = (BF.NetClient)translator.FastGetCSObj(L, 1);
|
|
|
|
|
|
|
|
{
|
|
|
|
gen_to_be_invoked.Start( );
|
|
|
|
|
|
|
|
return 0;
|
|
}
|
|
|
|
} catch(System.Exception gen_e) {
|
|
return LuaAPI.luaL_error(L, "c# exception:" + gen_e);
|
|
}
|
|
|
|
}
|
|
|
|
[MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))]
|
|
static int _m_Shutdown(RealStatePtr L)
|
|
{
|
|
try {
|
|
|
|
ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);
|
|
|
|
|
|
BF.NetClient gen_to_be_invoked = (BF.NetClient)translator.FastGetCSObj(L, 1);
|
|
|
|
|
|
|
|
{
|
|
|
|
gen_to_be_invoked.Shutdown( );
|
|
|
|
|
|
|
|
return 0;
|
|
}
|
|
|
|
} catch(System.Exception gen_e) {
|
|
return LuaAPI.luaL_error(L, "c# exception:" + gen_e);
|
|
}
|
|
|
|
}
|
|
|
|
[MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))]
|
|
static int _m_SetupService(RealStatePtr L)
|
|
{
|
|
try {
|
|
|
|
ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);
|
|
|
|
|
|
BF.NetClient gen_to_be_invoked = (BF.NetClient)translator.FastGetCSObj(L, 1);
|
|
|
|
|
|
|
|
{
|
|
BF.NetConfiguration _configuration = (BF.NetConfiguration)translator.GetObject(L, 2, typeof(BF.NetConfiguration));
|
|
|
|
gen_to_be_invoked.SetupService( _configuration );
|
|
|
|
|
|
|
|
return 0;
|
|
}
|
|
|
|
} catch(System.Exception gen_e) {
|
|
return LuaAPI.luaL_error(L, "c# exception:" + gen_e);
|
|
}
|
|
|
|
}
|
|
|
|
[MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))]
|
|
static int _m_Connect(RealStatePtr L)
|
|
{
|
|
try {
|
|
|
|
ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);
|
|
|
|
|
|
BF.NetClient gen_to_be_invoked = (BF.NetClient)translator.FastGetCSObj(L, 1);
|
|
|
|
|
|
int gen_param_count = LuaAPI.lua_gettop(L);
|
|
|
|
if(gen_param_count == 4&& translator.Assignable<BF.NetConnectConfiguration>(L, 2)&& (LuaAPI.lua_isnil(L, 3) || LuaAPI.lua_type(L, 3) == LuaTypes.LUA_TSTRING)&& LuaTypes.LUA_TNUMBER == LuaAPI.lua_type(L, 4))
|
|
{
|
|
BF.NetConnectConfiguration _configuration = (BF.NetConnectConfiguration)translator.GetObject(L, 2, typeof(BF.NetConnectConfiguration));
|
|
string _domainName = LuaAPI.lua_tostring(L, 3);
|
|
int _port = LuaAPI.xlua_tointeger(L, 4);
|
|
|
|
gen_to_be_invoked.Connect( _configuration, _domainName, _port );
|
|
|
|
|
|
|
|
return 0;
|
|
}
|
|
if(gen_param_count == 4&& translator.Assignable<BF.NetConnectConfiguration>(L, 2)&& translator.Assignable<System.Net.IPAddress>(L, 3)&& LuaTypes.LUA_TNUMBER == LuaAPI.lua_type(L, 4))
|
|
{
|
|
BF.NetConnectConfiguration _configuration = (BF.NetConnectConfiguration)translator.GetObject(L, 2, typeof(BF.NetConnectConfiguration));
|
|
System.Net.IPAddress _ipAddress = (System.Net.IPAddress)translator.GetObject(L, 3, typeof(System.Net.IPAddress));
|
|
int _port = LuaAPI.xlua_tointeger(L, 4);
|
|
|
|
gen_to_be_invoked.Connect( _configuration, _ipAddress, _port );
|
|
|
|
|
|
|
|
return 0;
|
|
}
|
|
|
|
} catch(System.Exception gen_e) {
|
|
return LuaAPI.luaL_error(L, "c# exception:" + gen_e);
|
|
}
|
|
|
|
return LuaAPI.luaL_error(L, "invalid arguments to BF.NetClient.Connect!");
|
|
|
|
}
|
|
|
|
[MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))]
|
|
static int _m_Reconnect(RealStatePtr L)
|
|
{
|
|
try {
|
|
|
|
ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);
|
|
|
|
|
|
BF.NetClient gen_to_be_invoked = (BF.NetClient)translator.FastGetCSObj(L, 1);
|
|
|
|
|
|
|
|
{
|
|
string _uniqueIdentifier = LuaAPI.lua_tostring(L, 2);
|
|
|
|
gen_to_be_invoked.Reconnect( _uniqueIdentifier );
|
|
|
|
|
|
|
|
return 0;
|
|
}
|
|
|
|
} catch(System.Exception gen_e) {
|
|
return LuaAPI.luaL_error(L, "c# exception:" + gen_e);
|
|
}
|
|
|
|
}
|
|
|
|
[MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))]
|
|
static int _m_Close(RealStatePtr L)
|
|
{
|
|
try {
|
|
|
|
ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);
|
|
|
|
|
|
BF.NetClient gen_to_be_invoked = (BF.NetClient)translator.FastGetCSObj(L, 1);
|
|
|
|
|
|
|
|
{
|
|
string _uniqueIdentifier = LuaAPI.lua_tostring(L, 2);
|
|
|
|
gen_to_be_invoked.Close( _uniqueIdentifier );
|
|
|
|
|
|
|
|
return 0;
|
|
}
|
|
|
|
} catch(System.Exception gen_e) {
|
|
return LuaAPI.luaL_error(L, "c# exception:" + gen_e);
|
|
}
|
|
|
|
}
|
|
|
|
[MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))]
|
|
static int _m_Send(RealStatePtr L)
|
|
{
|
|
try {
|
|
|
|
ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);
|
|
|
|
|
|
BF.NetClient gen_to_be_invoked = (BF.NetClient)translator.FastGetCSObj(L, 1);
|
|
|
|
|
|
|
|
{
|
|
string _uniqueIdentifier = LuaAPI.lua_tostring(L, 2);
|
|
uint _group = LuaAPI.xlua_touint(L, 3);
|
|
byte _cmd = (byte)LuaAPI.xlua_tointeger(L, 4);
|
|
byte[] _data = LuaAPI.lua_tobytes(L, 5);
|
|
|
|
var gen_ret = gen_to_be_invoked.Send( _uniqueIdentifier, _group, _cmd, _data );
|
|
translator.Push(L, gen_ret);
|
|
|
|
|
|
|
|
return 1;
|
|
}
|
|
|
|
} catch(System.Exception gen_e) {
|
|
return LuaAPI.luaL_error(L, "c# exception:" + gen_e);
|
|
}
|
|
|
|
}
|
|
|
|
[MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))]
|
|
static int _m_ReadMessage(RealStatePtr L)
|
|
{
|
|
try {
|
|
|
|
ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);
|
|
|
|
|
|
BF.NetClient gen_to_be_invoked = (BF.NetClient)translator.FastGetCSObj(L, 1);
|
|
|
|
|
|
|
|
{
|
|
string _uniqueIdentifier = LuaAPI.lua_tostring(L, 2);
|
|
|
|
var gen_ret = gen_to_be_invoked.ReadMessage( _uniqueIdentifier );
|
|
translator.PushAny(L, gen_ret);
|
|
|
|
|
|
|
|
return 1;
|
|
}
|
|
|
|
} catch(System.Exception gen_e) {
|
|
return LuaAPI.luaL_error(L, "c# exception:" + gen_e);
|
|
}
|
|
|
|
}
|
|
|
|
[MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))]
|
|
static int _m_RecycleMessage(RealStatePtr L)
|
|
{
|
|
try {
|
|
|
|
ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);
|
|
|
|
|
|
BF.NetClient gen_to_be_invoked = (BF.NetClient)translator.FastGetCSObj(L, 1);
|
|
|
|
|
|
|
|
{
|
|
string _uniqueIdentifier = LuaAPI.lua_tostring(L, 2);
|
|
BF.INetIncomingMessage _message = (BF.INetIncomingMessage)translator.GetObject(L, 3, typeof(BF.INetIncomingMessage));
|
|
|
|
gen_to_be_invoked.RecycleMessage( _uniqueIdentifier, _message );
|
|
|
|
|
|
|
|
return 0;
|
|
}
|
|
|
|
} catch(System.Exception gen_e) {
|
|
return LuaAPI.luaL_error(L, "c# exception:" + gen_e);
|
|
}
|
|
|
|
}
|
|
|
|
[MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))]
|
|
static int _m_GetConnectStatus(RealStatePtr L)
|
|
{
|
|
try {
|
|
|
|
ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);
|
|
|
|
|
|
BF.NetClient gen_to_be_invoked = (BF.NetClient)translator.FastGetCSObj(L, 1);
|
|
|
|
|
|
|
|
{
|
|
string _uniqueIdentifier = LuaAPI.lua_tostring(L, 2);
|
|
|
|
var gen_ret = gen_to_be_invoked.GetConnectStatus( _uniqueIdentifier );
|
|
translator.Push(L, gen_ret);
|
|
|
|
|
|
|
|
return 1;
|
|
}
|
|
|
|
} catch(System.Exception gen_e) {
|
|
return LuaAPI.luaL_error(L, "c# exception:" + gen_e);
|
|
}
|
|
|
|
}
|
|
|
|
[MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))]
|
|
static int _m_GetConnectIP(RealStatePtr L)
|
|
{
|
|
try {
|
|
|
|
ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);
|
|
|
|
|
|
BF.NetClient gen_to_be_invoked = (BF.NetClient)translator.FastGetCSObj(L, 1);
|
|
|
|
|
|
|
|
{
|
|
string _uniqueIdentifier = LuaAPI.lua_tostring(L, 2);
|
|
|
|
var gen_ret = gen_to_be_invoked.GetConnectIP( _uniqueIdentifier );
|
|
LuaAPI.lua_pushstring(L, gen_ret);
|
|
|
|
|
|
|
|
return 1;
|
|
}
|
|
|
|
} catch(System.Exception gen_e) {
|
|
return LuaAPI.luaL_error(L, "c# exception:" + gen_e);
|
|
}
|
|
|
|
}
|
|
|
|
[MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))]
|
|
static int _m_GetServerTimestamp(RealStatePtr L)
|
|
{
|
|
try {
|
|
|
|
ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);
|
|
|
|
|
|
BF.NetClient gen_to_be_invoked = (BF.NetClient)translator.FastGetCSObj(L, 1);
|
|
|
|
|
|
|
|
{
|
|
string _uniqueIdentifier = LuaAPI.lua_tostring(L, 2);
|
|
|
|
var gen_ret = gen_to_be_invoked.GetServerTimestamp( _uniqueIdentifier );
|
|
LuaAPI.lua_pushint64(L, gen_ret);
|
|
|
|
|
|
|
|
return 1;
|
|
}
|
|
|
|
} catch(System.Exception gen_e) {
|
|
return LuaAPI.luaL_error(L, "c# exception:" + gen_e);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))]
|
|
static int _g_get_Instance(RealStatePtr L)
|
|
{
|
|
try {
|
|
ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);
|
|
translator.Push(L, BF.NetClient.Instance);
|
|
} catch(System.Exception gen_e) {
|
|
return LuaAPI.luaL_error(L, "c# exception:" + gen_e);
|
|
}
|
|
return 1;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
}
|