### 新增IO 类
### 新增MD5 类 ### 新增Mysql 类 ### 新增Timer 类
This commit is contained in:
@@ -15,4 +15,39 @@ class GameManager extends Base_C_Object {
|
||||
local C_Party = Sq_GameManager_GetParty(C_Object);
|
||||
return Party(C_Party);
|
||||
}
|
||||
|
||||
//设置游戏最大等级
|
||||
function SetGameMaxLevel(MaxLevel) {
|
||||
NativePointer("0x8360C38").add(3).writeU8(MaxLevel);
|
||||
NativePointer("0x8360C76").add(3).writeU8(MaxLevel);
|
||||
NativePointer("0x8360CC1").add(3).writeU8(MaxLevel);
|
||||
NativePointer("0x84EF802").add(3).writeU8(MaxLevel);
|
||||
NativePointer("0x858F002").add(3).writeU8(MaxLevel);
|
||||
NativePointer("0x865A5C0").add(1).writeU8(MaxLevel);
|
||||
NativePointer("0x865B091").add(4).writeU8(MaxLevel);
|
||||
NativePointer("0x865B757").add(4).writeU8(MaxLevel);
|
||||
NativePointer("0x8662F53").add(2).writeU8(MaxLevel);
|
||||
NativePointer("0x86630F0").add(3).writeU8(MaxLevel);
|
||||
NativePointer("0x86638F4").add(2).writeU8(MaxLevel);
|
||||
NativePointer("0x8665D24").add(4).writeU8(MaxLevel);
|
||||
NativePointer("0x8666E9A").add(2).writeU8(MaxLevel);
|
||||
NativePointer("0x866A4A6").add(2).writeU8(MaxLevel);
|
||||
NativePointer("0x866A657").add(2).writeU8(MaxLevel);
|
||||
NativePointer("0x866A926").add(3).writeU8(MaxLevel);
|
||||
NativePointer("0x866A93F").add(2).writeU8(MaxLevel);
|
||||
NativePointer("0x867AEC0").add(2).writeU8(MaxLevel);
|
||||
NativePointer("0x8689D48").add(3).writeU8(MaxLevel);
|
||||
NativePointer("0x868fecb").add(3).writeU8(MaxLevel);
|
||||
NativePointer("0x868fed4").add(6).writeU8(MaxLevel);
|
||||
}
|
||||
|
||||
//设置装备解锁需要时间
|
||||
function SetItemLockTime(time) {
|
||||
NativePointer("0x8402D29").writeInt(time);
|
||||
NativePointer("0x854242F").writeInt(time);
|
||||
NativePointer("0x854274D").writeInt(time);
|
||||
NativePointer("0x854296F").writeInt(time);
|
||||
NativePointer("0x8542AD9").writeInt(time);
|
||||
NativePointer("0x8542BDE").writeInt(time);
|
||||
}
|
||||
}
|
||||
76
Dps_A/BaseClass/IOClass/IOClass.nut
Normal file
76
Dps_A/BaseClass/IOClass/IOClass.nut
Normal file
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
文件名:IOClass.nut
|
||||
路径:Dps_A/BaseClass/IOClass/IOClass.nut
|
||||
创建日期:2024-09-19 14:13
|
||||
文件用途:IO流类
|
||||
*/
|
||||
class IO extends Base_C_Object {
|
||||
_Fopen_Address = Module.getExportByName(null, "fopen");
|
||||
_Fgetc_Address = Module.getExportByName(null, "fgetc");
|
||||
_Fputc_Address = Module.getExportByName(null, "fputc");
|
||||
_Fgets_Address = Module.getExportByName(null, "fgets");
|
||||
_Fputs_Address = Module.getExportByName(null, "fputs");
|
||||
_Fread_Address = Module.getExportByName(null, "fread");
|
||||
_Fwrite_Address = Module.getExportByName(null, "fwrite");
|
||||
_Fclose_Address = Module.getExportByName(null, "fclose");
|
||||
_Fseek_Address = Module.getExportByName(null, "fseek");
|
||||
_Ftell_Address = Module.getExportByName(null, "ftell");
|
||||
_Rewind_Address = Module.getExportByName(null, "rewind");
|
||||
|
||||
|
||||
|
||||
Pos = 0;
|
||||
|
||||
constructor(FileName, Modes) {
|
||||
local FileObj = Sq_CallFunc(_Fopen_Address, "pointer", ["pointer", "pointer"], Str_Ptr(FileName), Str_Ptr(Modes));
|
||||
if (FileObj) {
|
||||
base.constructor(FileObj);
|
||||
} else error("文件打开错误! FileName: " + FileName);
|
||||
}
|
||||
|
||||
//读取一行
|
||||
function ReadLine() {
|
||||
local Buffer = Memory.alloc(256);
|
||||
local RetFlag = Sq_CallFunc(_Fgets_Address, "pointer", ["pointer", "int", "pointer"], Buffer.C_Object, 256, this.C_Object);
|
||||
if (RetFlag)
|
||||
return Buffer.readUtf8String();
|
||||
}
|
||||
|
||||
//读取一个
|
||||
function Read() {
|
||||
local RetFlag = Sq_CallFunc(_Fgetc_Address, "char", ["pointer"], this.C_Object);
|
||||
if (RetFlag) {
|
||||
return RetFlag;
|
||||
}
|
||||
}
|
||||
|
||||
//读取指定大小
|
||||
function ReadBuffer(size) {
|
||||
local Buffer = Memory.alloc(size);
|
||||
local RetFlag = Sq_CallFunc(_Fread_Address, "int", ["pointer", "int", "int", "pointer"], Buffer.C_Object, 1, size, this.C_Object);
|
||||
if (RetFlag > 0) {
|
||||
return {
|
||||
count = RetFlag,
|
||||
str = Buffer.readUtf8String(RetFlag)
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
count = 0,
|
||||
str = ""
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//写入字符串
|
||||
function Write(Str) {
|
||||
local Buffer = Memory.allocUtf8String(Str);
|
||||
Sq_CallFunc(_Fputs_Address, "int", ["pointer", "pointer"], Buffer.C_Object, this.C_Object);
|
||||
}
|
||||
|
||||
|
||||
//关闭文件
|
||||
function Close() {
|
||||
Sq_CallFunc(_Fclose_Address, "pointer", ["pointer"], this.C_Object);
|
||||
}
|
||||
}
|
||||
42
Dps_A/BaseClass/MD5Class/MD5Class.nut
Normal file
42
Dps_A/BaseClass/MD5Class/MD5Class.nut
Normal file
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
文件名:MD5Class.nut
|
||||
路径:Dps_A/BaseClass/MD5Class/MD5Class.nut
|
||||
创建日期:2024-09-20 00:06
|
||||
文件用途:MD5类
|
||||
*/
|
||||
class MD5 {
|
||||
MD5_Init_ptr = Module.getExportByName(null, "MD5_Init");
|
||||
MD5_Update_ptr = Module.getExportByName(null, "MD5_Update");
|
||||
MD5_Final_ptr = Module.getExportByName(null, "MD5_Final");
|
||||
|
||||
function MD5_Init(Ctx) {
|
||||
Sq_CallFunc(MD5_Init_ptr, "void", ["pointer"], Ctx);
|
||||
}
|
||||
|
||||
function MD5_Update(Ctx, Buffer, Size) {
|
||||
Sq_CallFunc(MD5_Update_ptr, "void", ["pointer", "pointer", "int"], Ctx, Buffer, Size);
|
||||
}
|
||||
|
||||
function MD5_Final(Ctx, Result) {
|
||||
Sq_CallFunc(MD5_Final_ptr, "void", ["pointer", "pointer"], Ctx, Result);
|
||||
}
|
||||
|
||||
function GetFile(FileName) {
|
||||
local Io = IO(FileName, "r+");
|
||||
|
||||
local Ctx = Memory.alloc(0x100);
|
||||
MD5.MD5_Init(Ctx.C_Object);
|
||||
|
||||
while (true) {
|
||||
local Buffer = Memory.alloc(0x1000);
|
||||
local Res = Io.ReadBuffer(0x1000);
|
||||
if (Res.count == 0) break;
|
||||
MD5.MD5_Update(Ctx.C_Object, Memory.allocUtf8String(Res.str).C_Object, Res.count);
|
||||
}
|
||||
|
||||
local Result = Memory.alloc(16);
|
||||
MD5.MD5_Final(Result.C_Object, Ctx.C_Object);
|
||||
Io.Close();
|
||||
return Result.readUtf8String(16);
|
||||
}
|
||||
}
|
||||
183
Dps_A/BaseClass/MemoryClass/MemoryClass.nut
Normal file
183
Dps_A/BaseClass/MemoryClass/MemoryClass.nut
Normal file
@@ -0,0 +1,183 @@
|
||||
/*
|
||||
文件名:MemoryClass.nut
|
||||
路径:Dps_A/BaseClass/MemoryClass/MemoryClass.nut
|
||||
创建日期:2024-09-17 08:23
|
||||
文件用途:内存类
|
||||
*/
|
||||
class Memory {
|
||||
|
||||
function alloc(Size) {
|
||||
return NativePointer(Size);
|
||||
}
|
||||
|
||||
function allocUtf8String(Str) {
|
||||
return NativePointer(Str_Ptr(Str));
|
||||
}
|
||||
}
|
||||
|
||||
class NativePointer extends Base_C_Object {
|
||||
|
||||
constructor(T) {
|
||||
if (typeof T == "integer") {
|
||||
base.constructor(Sq_New_Point(T));
|
||||
//注册销毁伪析构
|
||||
Register_Destruction(C_Object, this);
|
||||
} else if (typeof T == "userdata") {
|
||||
base.constructor(T);
|
||||
} else if (typeof T == "string") {
|
||||
base.constructor(S_Ptr(T));
|
||||
}
|
||||
}
|
||||
|
||||
function add(intoffset) {
|
||||
this.C_Object = Sq_PointerOperation(this.C_Object, intoffset, "+");
|
||||
return this;
|
||||
}
|
||||
|
||||
function sub(intoffset) {
|
||||
this.C_Object = Sq_PointerOperation(this.C_Object, intoffset, "-");
|
||||
return this;
|
||||
}
|
||||
|
||||
function writeByteArray(arr) {
|
||||
Sq_Memory_WriteByteArr(this.C_Object, arr);
|
||||
}
|
||||
|
||||
function readByteArray(size) {
|
||||
local PointB = Sq_Point2Blob(this.C_Object, size);
|
||||
local arr = [];
|
||||
foreach(value in PointB) {
|
||||
arr.append(value);
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
|
||||
|
||||
function write(value, type) {
|
||||
local Buf = blob(0);
|
||||
Buf.writen(value, type);
|
||||
local arr = [];
|
||||
foreach(value in Buf) {
|
||||
arr.append(value);
|
||||
}
|
||||
writeByteArray(arr);
|
||||
}
|
||||
|
||||
function writeS8(value) {
|
||||
write(value, 'c');
|
||||
}
|
||||
|
||||
function writeU8(value) {
|
||||
write(value, 'b');
|
||||
}
|
||||
|
||||
function writeS16(value) {
|
||||
write(value, 's');
|
||||
}
|
||||
|
||||
function writeU16(value) {
|
||||
write(value, 'w');
|
||||
}
|
||||
|
||||
function writeS32(value) {
|
||||
write(value, 'i');
|
||||
}
|
||||
|
||||
function writeU32(value) {
|
||||
write(value, 'i');
|
||||
}
|
||||
|
||||
function writeShort(value) {
|
||||
write(value, 's');
|
||||
}
|
||||
|
||||
function writeUShort(value) {
|
||||
write(value, 'w');
|
||||
}
|
||||
|
||||
function writeInt(value) {
|
||||
write(value, 'i');
|
||||
}
|
||||
|
||||
function writeUInt(value) {
|
||||
write(value, 'i');
|
||||
}
|
||||
|
||||
function writeFloat(value) {
|
||||
write(value, 'f');
|
||||
}
|
||||
|
||||
function writeDouble(value) {
|
||||
write(value, 'd');
|
||||
}
|
||||
|
||||
|
||||
function read(type) {
|
||||
local Buf = Sq_Point2Blob(this.C_Object, 4);
|
||||
return Buf.readn(type);
|
||||
}
|
||||
|
||||
function readS8() {
|
||||
return read('c');
|
||||
}
|
||||
|
||||
function readU8() {
|
||||
return read('b');
|
||||
}
|
||||
|
||||
function readS16() {
|
||||
return read('s');
|
||||
}
|
||||
|
||||
function readU16() {
|
||||
return read('w');
|
||||
}
|
||||
|
||||
function readS32() {
|
||||
return read('i');
|
||||
}
|
||||
|
||||
function readU32() {
|
||||
return read('i');
|
||||
}
|
||||
|
||||
function readShort() {
|
||||
return read('s');
|
||||
}
|
||||
|
||||
function readUShort() {
|
||||
return read('w');
|
||||
}
|
||||
|
||||
function readInt() {
|
||||
return read('i');
|
||||
}
|
||||
|
||||
function readUInt() {
|
||||
return read('i');
|
||||
}
|
||||
|
||||
function readFloat() {
|
||||
return read('f');
|
||||
}
|
||||
|
||||
function readDouble() {
|
||||
return read('d');
|
||||
}
|
||||
|
||||
function readUtf8String(...) {
|
||||
if (vargv.len() > 0) {
|
||||
return Sq_Memory_ReadString(this.C_Object, vargv[0]);
|
||||
} else {
|
||||
return Sq_Memory_ReadString(this.C_Object);
|
||||
}
|
||||
}
|
||||
|
||||
function readPointer() {
|
||||
return Sq_ReadPoint(this.C_Object);
|
||||
}
|
||||
|
||||
function tostring() {
|
||||
return this.C_Object.tostring();
|
||||
}
|
||||
}
|
||||
16
Dps_A/BaseClass/MoudleClass/MoudleClass.nut
Normal file
16
Dps_A/BaseClass/MoudleClass/MoudleClass.nut
Normal file
@@ -0,0 +1,16 @@
|
||||
/*
|
||||
文件名:MoudleClass.nut
|
||||
路径:Dps_A/BaseClass/MoudleClass/MoudleClass.nut
|
||||
创建日期:2024-09-17 09:48
|
||||
文件用途:模块类
|
||||
*/
|
||||
class Module {
|
||||
|
||||
function getExportByName(ModuleName, FunctionName) {
|
||||
return Sq_getExportByName(ModuleName, FunctionName);
|
||||
}
|
||||
|
||||
function load() {
|
||||
|
||||
}
|
||||
}
|
||||
272
Dps_A/BaseClass/MysqlClass/MysqlClass.nut
Normal file
272
Dps_A/BaseClass/MysqlClass/MysqlClass.nut
Normal file
@@ -0,0 +1,272 @@
|
||||
/*
|
||||
文件名:MysqlClass.nut
|
||||
路径:Dps_A/BaseClass/MysqlClass/MysqlClass.nut
|
||||
创建日期:2024-09-16 21:23
|
||||
文件用途:数据库类
|
||||
*/
|
||||
class Mysql extends Base_C_Object {
|
||||
|
||||
// 0空闲 1任务中 2死亡
|
||||
State = 0;
|
||||
|
||||
constructor(Ip, Port, Name, Account, Password) {
|
||||
if (!Open(Ip, Port, Name, Account, Password)) error("数据库连接失败");
|
||||
}
|
||||
|
||||
/*
|
||||
* 读取mysql返回的数据,读取binary类型的字段
|
||||
* @param this.C_Object mysql数据库句柄
|
||||
* @param columnIndex 要读取的字段的位置
|
||||
*/
|
||||
function Open(db_ip, db_port, db_name, db_username, db_password) {
|
||||
base.constructor(Sq_New_Point(0x80000));
|
||||
Sq_CallFunc(S_Ptr("0x83F3AC8"), "pointer", ["pointer"], this.C_Object);
|
||||
Sq_CallFunc(S_Ptr("0x83F3CE4"), "int", ["pointer"], this.C_Object);
|
||||
//打开数据库句柄
|
||||
if (Sq_CallFunc(S_Ptr("0x83F4024"), "int", ["pointer", "pointer", "int", "pointer", "pointer", "pointer"],
|
||||
this.C_Object, db_ip, db_port, db_name, db_username, db_password)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function Fetch() {
|
||||
Sq_CallFunc(S_Ptr("0x83F44BC"), "int", ["pointer"], this.C_Object);
|
||||
}
|
||||
|
||||
function Close() {
|
||||
Sq_CallFunc(S_Ptr("0x83F3E74"), "int", ["pointer"], this.C_Object);
|
||||
Sq_Delete_Point(this.C_Object);
|
||||
State = 2;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 读取mysql返回的数据,读取string类型的字段
|
||||
* @param this.C_Object mysql数据库句柄
|
||||
* @param columnIndex 要读取的字段的位置
|
||||
*/
|
||||
function ReadStringColumn(columnIndex) {
|
||||
//MySQL_get_binary_length
|
||||
local binary_length = Sq_CallFunc(S_Ptr("0x81253DE"), "int", ["pointer", "int"], this.C_Object, columnIndex);
|
||||
local binary_length_point = Sq_New_Point(binary_length);
|
||||
//MySQL_get_binary
|
||||
if (1 == Sq_CallFunc(S_Ptr("0x812531A"), "int", ["pointer", "int", "pointer", "int"], this.C_Object, columnIndex, binary_length_point, binary_length)) {
|
||||
//读取string类型的数据
|
||||
local result = Sq_ReadAddressString(binary_length_point, binary_length);
|
||||
Sq_Delete_Point(binary_length_point);
|
||||
return result;
|
||||
}
|
||||
Sq_Delete_Point(binary_length_point);
|
||||
return null;
|
||||
}
|
||||
|
||||
/*
|
||||
* 读取mysql返回的数据,读取有符号int类型的字段
|
||||
* @param this.C_Object mysql数据库句柄
|
||||
* @param columnIndex 要读取的字段的位置
|
||||
*/
|
||||
function ReadIntColumn(columnIndex) {
|
||||
local intSizePoint = Sq_New_Point(4);
|
||||
//MySQL_get_int
|
||||
if (1 == Sq_CallFunc(S_Ptr("0x811692C"), "int", ["pointer", "int", "pointer"], this.C_Object, columnIndex, intSizePoint)) {
|
||||
//转为blob
|
||||
local blob = Sq_Point2Blob(intSizePoint, 4);
|
||||
//读取8位有符号整数
|
||||
local result = blob.readn('c');
|
||||
Sq_Delete_Point(intSizePoint);
|
||||
return result;
|
||||
}
|
||||
Sq_Delete_Point(intSizePoint);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 读取mysql返回的数据,读取无符号int类型的字段
|
||||
* @param this.C_Object mysql数据库句柄
|
||||
* @param columnIndex 要读取的字段的位置
|
||||
*/
|
||||
function ReadUIntColumn(columnIndex) {
|
||||
local intSizePoint = Sq_New_Point(4);
|
||||
//MySQL_get_uint
|
||||
if (1 == Sq_CallFunc(S_Ptr("0x80E22F2"), "int", ["pointer", "int", "pointer"], this.C_Object, columnIndex, intSizePoint)) {
|
||||
//转为blob
|
||||
local blob = Sq_Point2Blob(intSizePoint, 4);
|
||||
//读取8位无符号整数
|
||||
local result = blob.readn('b');
|
||||
Sq_Delete_Point(intSizePoint);
|
||||
return result;
|
||||
}
|
||||
Sq_Delete_Point(intSizePoint);
|
||||
return null;
|
||||
}
|
||||
|
||||
/*
|
||||
* 读取mysql返回的数据,读取float类型的字段
|
||||
* @param this.C_Object mysql数据库句柄
|
||||
* @param columnIndex 要读取的字段的位置
|
||||
*/
|
||||
function ReadFloatColumn(columnIndex) {
|
||||
local intSizePoint = Sq_New_Point(4);
|
||||
//MySQL_get_float
|
||||
if (1 == Sq_CallFunc(S_Ptr("0x844D6D0"), "int", ["pointer", "int", "pointer"], this.C_Object, columnIndex, intSizePoint)) {
|
||||
//转为blob
|
||||
local blob = Sq_Point2Blob(intSizePoint, 4);
|
||||
//读取32位浮点数
|
||||
local result = blob.readn('f');
|
||||
Sq_Delete_Point(intSizePoint);
|
||||
return result;
|
||||
}
|
||||
Sq_Delete_Point(intSizePoint);
|
||||
return null;
|
||||
}
|
||||
|
||||
/*
|
||||
* 读取mysql返回的数据,读取binary类型的字段
|
||||
* @param this.C_Object mysql数据库句柄
|
||||
* @param columnIndex 要读取的字段的位置
|
||||
*/
|
||||
function ReadBinaryColumn(columnIndex) {
|
||||
//MySQL_get_binary_length
|
||||
local binary_length = Sq_CallFunc(S_Ptr("0x81253DE"), "int", ["pointer", "int"], this.C_Object, columnIndex);
|
||||
if (binary_length > 0) {
|
||||
local binary_length_point = Sq_New_Point(binary_length);
|
||||
//MySQL_get_binary
|
||||
if (1 == Sq_CallFunc(S_Ptr("0x812531A"), "int", ["pointer", "int", "pointer", "int"], this.C_Object, columnIndex, binary_length_point, binary_length)) {
|
||||
//转为blob
|
||||
local blob = Sq_Point2Blob(binary_length_point, binary_length);
|
||||
Sq_Delete_Point(intSizePoint);
|
||||
return blob;
|
||||
}
|
||||
}
|
||||
Sq_Delete_Point(intSizePoint);
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* mysql查询,带返回结果,返回一个二维数组
|
||||
* @param {*} db_pointer 数据库句柄
|
||||
* @param {*} select_sql 要执行的查询语句
|
||||
* @param {*} column_type_list 返回结果的类型list,按select的column顺序,int,string,unit,float,binary
|
||||
* @returns
|
||||
*/
|
||||
function Select(select_sql, column_type_list) {
|
||||
local result_list = [];
|
||||
if (Exec_Sql(select_sql)) {
|
||||
//获取查询到的数据总数
|
||||
local row_count = Sq_CallFunc(S_Ptr("0x80E236C"), "int", ["pointer"], this.C_Object);
|
||||
if (row_count > 0) {
|
||||
for (local i = 0; i< row_count; i++) {
|
||||
Fetch();
|
||||
local row = [];
|
||||
for (local j = 0; j< column_type_list.len(); j++) {
|
||||
if (column_type_list[j] == "int") {
|
||||
row.push(ReadIntColumn(j));
|
||||
}
|
||||
if (column_type_list[j] == "string") {
|
||||
row.push(ReadStringColumn(j));
|
||||
}
|
||||
if (column_type_list[j] == "uint") {
|
||||
row.push(ReadUIntColumn(j));
|
||||
}
|
||||
if (column_type_list[j] == "float") {
|
||||
row.push(ReadFloatColumn(j));
|
||||
}
|
||||
if (column_type_list[j] == "binary") {
|
||||
row.push(ReadBinaryColumn(j));
|
||||
}
|
||||
}
|
||||
result_list.push(row);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result_list;
|
||||
}
|
||||
|
||||
//执行查询返回执行是否成功
|
||||
function Exec_Sql(sql) {
|
||||
local sql_ptr = Str_Ptr(sql);
|
||||
//set query
|
||||
local set_query = Sq_CallFunc(S_Ptr("0x83F41C0"), "int", ["pointer", "pointer"], this.C_Object, sql_ptr);
|
||||
//执行sql
|
||||
local sql_exec_result = Sq_CallFunc(S_Ptr("0x83F4326"), "int", ["pointer", "int"], this.C_Object, 1);
|
||||
return sql_exec_result;
|
||||
}
|
||||
|
||||
|
||||
//获取服务端版本
|
||||
function GetServerVersion() {
|
||||
return Sq_CallFunc(S_Ptr("0x83F460C"), "int", ["pointer"], this.C_Object);
|
||||
}
|
||||
//获取客户端版本
|
||||
function GetClientVersion() {
|
||||
return Sq_CallFunc(S_Ptr("0x83F4622"), "int", ["pointer"], this.C_Object);
|
||||
}
|
||||
}
|
||||
|
||||
class MysqlPool {
|
||||
|
||||
// 用于存储数据库的 IP 地址
|
||||
db_ip = null;
|
||||
// 用于存储数据库的端口号
|
||||
db_port = null;
|
||||
// 用于存储数据库的名称
|
||||
db_name = null;
|
||||
// 用于存储数据库的用户名
|
||||
db_username = null;
|
||||
// 用于存储数据库的密码
|
||||
db_password = null;
|
||||
|
||||
//连接池大小
|
||||
PoolSize = 10;
|
||||
//连接编码
|
||||
Charset = "latin1";
|
||||
//连接池
|
||||
PoolList = null;
|
||||
|
||||
constructor() {
|
||||
PoolList = [];
|
||||
getroottable()._MysqlPoolObject <- this;
|
||||
}
|
||||
|
||||
function GetInstance() {
|
||||
// if (!(getroottable().rawin("_MysqlPoolObject"))) MysqlPool();
|
||||
MysqlPool();
|
||||
return getroottable()._MysqlPoolObject;
|
||||
}
|
||||
|
||||
//设置基础配置
|
||||
function SetBaseConfiguration(Ip, Port, Account, Password) {
|
||||
db_ip = Str_Ptr(Ip);
|
||||
db_port = Port;
|
||||
db_name = Str_Ptr("taiwan_cain");
|
||||
db_username = Str_Ptr(Account);
|
||||
db_password = Str_Ptr(Password);
|
||||
}
|
||||
|
||||
//初始化连接池
|
||||
function Init() {
|
||||
for (local i = 0; i< PoolSize; i++) {
|
||||
local Buffer = Mysql(db_ip, db_port, db_name, db_username, db_password);
|
||||
Buffer.Exec_Sql(format("SET NAMES %s", Charset));
|
||||
PoolList.append(Buffer);
|
||||
// print("创建了一条连接,编号: " + i + ",地址: " + Buffer + ", 指针地址: " + Buffer.C_Object);
|
||||
}
|
||||
}
|
||||
|
||||
function GetConnect() {
|
||||
local _Connect = PoolList.pop();
|
||||
if (_Connect.State == 0) {
|
||||
_Connect.State = 1;
|
||||
return _Connect;
|
||||
}
|
||||
}
|
||||
|
||||
function PutConnect(_Connect) {
|
||||
if (_Connect.State == 1) {
|
||||
_Connect.State = 0;
|
||||
PoolList.append(_Connect);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -55,4 +55,9 @@ class PvfItem extends Base_C_Object {
|
||||
return PvfItem(Ret);
|
||||
} else return null;
|
||||
}
|
||||
//Public
|
||||
function GetPvfData(Idx) {
|
||||
local Ret = Sq_CallFunc(S_Ptr("0x835FA32"), "pointer", ["pointer", "int"], Sq_CallFunc(S_Ptr("0x80CC19B"), "pointer", []), Idx);
|
||||
return NativePointer(Ret);
|
||||
}
|
||||
}
|
||||
280
Dps_A/BaseClass/RedBlackTreeClass/RedBlackTreeClass.nut
Normal file
280
Dps_A/BaseClass/RedBlackTreeClass/RedBlackTreeClass.nut
Normal file
@@ -0,0 +1,280 @@
|
||||
/*
|
||||
文件名:RedBlackTreeClass.nut
|
||||
路径:Dps_A/BaseClass/RedBlackTreeClass/RedBlackTreeClass.nut
|
||||
创建日期:2024-09-19 12:42
|
||||
文件用途:红黑树类
|
||||
*/
|
||||
// 红黑树节点类
|
||||
class RBTreeNode {
|
||||
key = null;
|
||||
time = null;
|
||||
left = null;
|
||||
right = null;
|
||||
parent = null;
|
||||
color = null;
|
||||
Info = null;
|
||||
constructor(key, func_info) {
|
||||
this.key = key;
|
||||
this.time = key;
|
||||
this.Info = func_info;
|
||||
this.left = null;
|
||||
this.right = null;
|
||||
this.parent = null;
|
||||
this.color = "red";
|
||||
}
|
||||
|
||||
function _tyoeof() {
|
||||
return "RBTreeNode";
|
||||
}
|
||||
}
|
||||
|
||||
// 红黑树类
|
||||
class RedBlackTree {
|
||||
nil = null;
|
||||
root = null;
|
||||
size = 0;
|
||||
|
||||
function _tyoeof() {
|
||||
return "RedBlackTree";
|
||||
}
|
||||
|
||||
constructor() {
|
||||
this.nil = RBTreeNode(null, null);
|
||||
this.root = this.nil;
|
||||
}
|
||||
|
||||
function insert(key, func_info) {
|
||||
local z = RBTreeNode(key, func_info);
|
||||
local y = this.nil;
|
||||
local x = this.root;
|
||||
while (x != this.nil) {
|
||||
y = x;
|
||||
if (z.key< x.key) {
|
||||
x = x.left;
|
||||
} else {
|
||||
x = x.right;
|
||||
}
|
||||
}
|
||||
z.parent = y;
|
||||
if (y == this.nil) {
|
||||
this.root = z;
|
||||
} else if (z.key< y.key) {
|
||||
y.left = z;
|
||||
} else {
|
||||
y.right = z;
|
||||
}
|
||||
z.left = this.nil;
|
||||
z.right = this.nil;
|
||||
z.color = "red";
|
||||
this.insertFixup(z);
|
||||
this.size++;
|
||||
}
|
||||
|
||||
function insertFixup(z) {
|
||||
while (z.parent.color == "red") {
|
||||
if (z.parent.parent && z.parent == z.parent.parent.left) {
|
||||
local y = z.parent.parent.right;
|
||||
if (y.color == "red") {
|
||||
z.parent.color = "black";
|
||||
y.color = "black";
|
||||
z.parent.parent.color = "red";
|
||||
z = z.parent.parent;
|
||||
} else {
|
||||
if (z == z.parent.right) {
|
||||
z = z.parent;
|
||||
this.leftRotate(z);
|
||||
}
|
||||
z.parent.color = "black";
|
||||
z.parent.parent.color = "red";
|
||||
this.rightRotate(z.parent.parent);
|
||||
}
|
||||
} else {
|
||||
if (z.parent.parent && z.parent.parent.left.color == "red") {
|
||||
z.parent.color = "black";
|
||||
z.parent.parent.left.color = "black";
|
||||
z.parent.parent.color = "red";
|
||||
z = z.parent.parent;
|
||||
} else {
|
||||
if (z == z.parent.left) {
|
||||
z = z.parent;
|
||||
this.rightRotate(z);
|
||||
}
|
||||
z.parent.color = "black";
|
||||
if (z.parent.parent) z.parent.parent.color = "red";
|
||||
this.leftRotate(z.parent.parent);
|
||||
}
|
||||
}
|
||||
}
|
||||
this.root.color = "black";
|
||||
}
|
||||
|
||||
function leftRotate(x) {
|
||||
if (!x) return;
|
||||
local y = x.right;
|
||||
x.right = y.left;
|
||||
if (y.left != this.nil) {
|
||||
y.left.parent = x;
|
||||
}
|
||||
y.parent = x.parent;
|
||||
if (x.parent == this.nil) {
|
||||
this.root = y;
|
||||
} else if (x == x.parent.left) {
|
||||
x.parent.left = y;
|
||||
} else {
|
||||
x.parent.right = y;
|
||||
}
|
||||
y.left = x;
|
||||
x.parent = y;
|
||||
}
|
||||
|
||||
function rightRotate(x) {
|
||||
local y = x.left;
|
||||
x.left = y.right;
|
||||
if (y.right != this.nil) {
|
||||
y.right.parent = x;
|
||||
}
|
||||
y.parent = x.parent;
|
||||
if (x.parent == this.nil) {
|
||||
this.root = y;
|
||||
} else if (x == x.parent.left) {
|
||||
x.parent.left = y;
|
||||
} else {
|
||||
x.parent.right = y;
|
||||
}
|
||||
y.right = x;
|
||||
x.parent = y;
|
||||
}
|
||||
|
||||
|
||||
function minimum(...) {
|
||||
local node = this.root;
|
||||
if (vargv.len() > 0) node = vargv[0];
|
||||
while (node.left != this.nil) {
|
||||
node = node.left;
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
function transplant(u, v) {
|
||||
if (u.parent == this.nil) {
|
||||
this.root = v;
|
||||
} else if (u == u.parent.left) {
|
||||
u.parent.left = v;
|
||||
} else {
|
||||
u.parent.right = v;
|
||||
}
|
||||
v.parent = u.parent;
|
||||
}
|
||||
|
||||
function deleteFixup(x) {
|
||||
while (x != this.root && x.color == "black") {
|
||||
if (x == x.parent.left) {
|
||||
local w = x.parent.right;
|
||||
if (w.color == "red") {
|
||||
w.color = "black";
|
||||
x.parent.color = "red";
|
||||
this.leftRotate(x.parent);
|
||||
w = x.parent.right;
|
||||
}
|
||||
if (w.left.color == "black" && w.right.color == "black") {
|
||||
w.color = "red";
|
||||
x = x.parent;
|
||||
} else {
|
||||
if (w.right.color == "black") {
|
||||
w.left.color = "black";
|
||||
w.color = "red";
|
||||
this.rightRotate(w);
|
||||
w = x.parent.right;
|
||||
}
|
||||
w.color = x.parent.color;
|
||||
x.parent.color = "black";
|
||||
w.right.color = "black";
|
||||
this.leftRotate(x.parent);
|
||||
x = this.root;
|
||||
}
|
||||
} else {
|
||||
local w = x.parent.left;
|
||||
if (w.color == "red") {
|
||||
w.color = "black";
|
||||
x.parent.color = "red";
|
||||
this.rightRotate(x.parent);
|
||||
w = x.parent.left;
|
||||
}
|
||||
if (w.right.color == "black" && w.left.color == "black") {
|
||||
w.color = "red";
|
||||
x = x.parent;
|
||||
} else {
|
||||
if (w.left.color == "black") {
|
||||
w.right.color = "black";
|
||||
w.color = "red";
|
||||
this.leftRotate(w);
|
||||
w = x.parent.left;
|
||||
}
|
||||
w.color = x.parent.color;
|
||||
x.parent.color = "black";
|
||||
w.left.color = "black";
|
||||
this.rightRotate(x.parent);
|
||||
x = this.root;
|
||||
}
|
||||
}
|
||||
}
|
||||
x.color = "black";
|
||||
}
|
||||
|
||||
function deleteNode(z) {
|
||||
local y = z;
|
||||
local yOriginalColor = y.color;
|
||||
local x;
|
||||
if (z.left == this.nil) {
|
||||
x = z.right;
|
||||
this.transplant(z, z.right);
|
||||
} else if (z.right == this.nil) {
|
||||
x = z.left;
|
||||
this.transplant(z, z.left);
|
||||
} else {
|
||||
y = this.minimum(z.right);
|
||||
yOriginalColor = y.color;
|
||||
x = y.right;
|
||||
if (y.parent == z) {
|
||||
x.parent = y;
|
||||
} else {
|
||||
this.transplant(y, y.right);
|
||||
y.right = z.right;
|
||||
y.right.parent = y;
|
||||
}
|
||||
this.transplant(z, y);
|
||||
y.left = z.left;
|
||||
y.left.parent = y;
|
||||
y.color = z.color;
|
||||
}
|
||||
if (yOriginalColor == "black") {
|
||||
this.deleteFixup(x);
|
||||
}
|
||||
this.size--;
|
||||
}
|
||||
|
||||
function inorderTraversal(...) {
|
||||
local node = this.root;
|
||||
if (vargv.len() > 0) node = vargv[0];
|
||||
if (node == this.nil) {
|
||||
return;
|
||||
}
|
||||
this.inorderTraversal(node.left);
|
||||
print(node.key + "(" + node.color + ") ");
|
||||
this.inorderTraversal(node.right);
|
||||
}
|
||||
|
||||
function getSize() {
|
||||
return this.size;
|
||||
}
|
||||
|
||||
function pop() {
|
||||
if (this.size <= 0) return null;
|
||||
local z = this.minimum();
|
||||
if (z != this.nil) {
|
||||
this.deleteNode(z);
|
||||
return z;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
58
Dps_A/BaseClass/TimerClass/TimerClass.nut
Normal file
58
Dps_A/BaseClass/TimerClass/TimerClass.nut
Normal file
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
文件名:TimerClass.nut
|
||||
路径:Dps_A/BaseClass/TimerClass/TimerClass.nut
|
||||
创建日期:2024-09-19 12:39
|
||||
文件用途:定时器类
|
||||
*/
|
||||
class Timer {
|
||||
//执行任务队列树
|
||||
Wait_Exec_Tree = null;
|
||||
|
||||
constructor() {
|
||||
Wait_Exec_Tree = RedBlackTree();
|
||||
|
||||
Cb_timer_dispatch_Func.rawset("__System__Timer__Event", Update.bindenv(this));
|
||||
}
|
||||
|
||||
function Update() {
|
||||
local Node = Wait_Exec_Tree.pop();
|
||||
if (!Node) {
|
||||
return;
|
||||
}
|
||||
//取得函数体
|
||||
local Info = Node.Info;
|
||||
//执行时间
|
||||
local exec_time = Node.time;
|
||||
//如果没到执行时间,放回去,等待下次扫描
|
||||
if (time() <= exec_time) {
|
||||
Wait_Exec_Tree.insert(exec_time, Node.Info);
|
||||
return;
|
||||
}
|
||||
//函数
|
||||
local func = Info[0];
|
||||
//参数
|
||||
local func_args = Info[1];
|
||||
//执行函数
|
||||
func.acall(func_args);
|
||||
}
|
||||
|
||||
function SetTimeOut(target_func, delay_time, ...) {
|
||||
local target_arg_list = [];
|
||||
target_arg_list.push(getroottable());
|
||||
for (local i = 0; i< vargv.len(); i++) {
|
||||
target_arg_list.push(vargv[i]);
|
||||
}
|
||||
//当前时间戳,单位:s
|
||||
local time_sec = time();
|
||||
//计算下一次执行的时间
|
||||
local exec_time_sec = time_sec + (delay_time - 1);
|
||||
|
||||
//设置下一次执行
|
||||
local func_info = [];
|
||||
|
||||
func_info.push(target_func);
|
||||
func_info.push(target_arg_list);
|
||||
|
||||
_Timer_Object.Wait_Exec_Tree.insert(exec_time_sec, func_info);
|
||||
}
|
||||
}
|
||||
@@ -215,6 +215,19 @@ class User extends Base_C_Object {
|
||||
Sq_Packet_Send(this.C_Object, SPacket.C_Object);
|
||||
}
|
||||
|
||||
//发送弹窗公告包(可自定义文字需要客户端修复233dll搭配)
|
||||
function SendNotiBox(Msg, Type) {
|
||||
local Pack = Packet();
|
||||
Pack.Put_Header(0, 233);
|
||||
Pack.Put_Byte(1);
|
||||
Pack.Put_Byte(5);
|
||||
Pack.Put_Int(Msg.len());
|
||||
Pack.Put_BinaryEx(Str_Ptr(Msg), Msg.len());
|
||||
Pack.Finalize(true);
|
||||
Sq_CallFunc(S_Ptr("0x867B8FE"), "int", ["pointer", "int", "pointer"], this.C_Object, Type, Pack.C_Object);
|
||||
Pack.Delete();
|
||||
}
|
||||
|
||||
//发送自定义包
|
||||
function SendJso(Jso) {
|
||||
local Str = Json.Encode(Jso);
|
||||
|
||||
@@ -204,4 +204,64 @@ class World {
|
||||
function SendPartyInfoToAll(Party) {
|
||||
Sq_GameWorld_SendPartyInfoToAll(Sq_Get_GameWorld(), Party.C_Object);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//获取在线玩家列表表头
|
||||
function api_gameworld_user_map_begin() {
|
||||
local Begin = Sq_New_Point(4);
|
||||
Sq_CallFunc(S_Ptr("0x80F78A6"), "int", ["pointer", "pointer"], Begin, Ptr_Operation_A2S(Sq_Get_GameWorld(), 308));
|
||||
return Begin;
|
||||
}
|
||||
|
||||
//获取在线玩家列表表尾
|
||||
function api_gameworld_user_map_end() {
|
||||
local End = Sq_New_Point(4);
|
||||
Sq_CallFunc(S_Ptr("0x80F78CC"), "int", ["pointer", "pointer"], End, Ptr_Operation_A2S(Sq_Get_GameWorld(), 308));
|
||||
return End;
|
||||
}
|
||||
|
||||
//获取当前正在遍历的玩家
|
||||
function api_gameworld_user_map_get(it) {
|
||||
local Buf = Sq_CallFunc(S_Ptr("0x80F7944"), "pointer", ["pointer"], it);
|
||||
local Buf2 = Ptr_Operation_A2S(Buf, 4);
|
||||
local Buf3 = Sq_ReadPoint(Buf2);
|
||||
return Buf3;
|
||||
}
|
||||
|
||||
//迭代器指针自增
|
||||
function api_gameworld_user_map_next(it) {
|
||||
local Next = Sq_New_Point(4);
|
||||
Sq_CallFunc(S_Ptr("0x80F7906"), "pointer", ["pointer", "pointer"], Next, it);
|
||||
Sq_Delete_Point(Next);
|
||||
return Next;
|
||||
}
|
||||
//获取在线玩家列表
|
||||
function GetOnlinePlayer() {
|
||||
local PlayerArr = [];
|
||||
//遍历在线玩家列表
|
||||
local it = api_gameworld_user_map_begin();
|
||||
local end = api_gameworld_user_map_end();
|
||||
|
||||
//判断在线玩家列表遍历是否已结束
|
||||
while (Sq_CallFunc(S_Ptr("0x80F78F2"), "bool", ["pointer", "pointer"], it, end)) {
|
||||
//当前被遍历到的玩家
|
||||
local user = api_gameworld_user_map_get(it);
|
||||
local SUser = User(user);
|
||||
if (SUser) PlayerArr.append(SUser);
|
||||
//继续遍历下一个玩家
|
||||
api_gameworld_user_map_next(it);
|
||||
}
|
||||
|
||||
Sq_Delete_Point(it);
|
||||
Sq_Delete_Point(end);
|
||||
return PlayerArr;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user