-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from pwnsky/dev
Dev
- Loading branch information
Showing
38 changed files
with
546 additions
and
538 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,6 @@ | |
-- Author: i0gan | ||
-- Email : [email protected] | ||
-- Date : 2022-12-03 | ||
-- Github: https://github.com/i0gan/Squick | ||
-- Description: 数据重置计时器,支持 每天初重置、每月初重置、每年初重置。 | ||
----------------------------------------------------------------------------- | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,6 @@ | |
-- Author: i0gan | ||
-- Email : [email protected] | ||
-- Date : 2022-12-03 | ||
-- Github: https://github.com/pwnsky/squick | ||
-- Description: 提供面向对象的支持 | ||
----------------------------------------------------------------------------- | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,6 @@ | |
-- Author: i0gan | ||
-- Email : [email protected] | ||
-- Date : 2022-12-04 | ||
-- Github: https://github.com/i0gan/Squick | ||
-- Description: 打印table | ||
----------------------------------------------------------------------------- | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
----------------------------------------------------------------------------- | ||
-- Author: i0gan | ||
-- Email : [email protected] | ||
-- Date : 2023-09-29 | ||
-- Description: Query async | ||
----------------------------------------------------------------------------- | ||
|
||
QueryAsync = { | ||
query_id = 0; | ||
co = {} | ||
} | ||
|
||
function QueryAsync:QueryInit() | ||
self.query_id = self.query_id + 1 % 1000000 | ||
return self.query_id | ||
end | ||
|
||
function QueryAsync:QueryAwait(query_id) | ||
self.co[query_id] = coroutine.running() | ||
return coroutine.yield() | ||
end | ||
|
||
function QueryAsync:QueryClean(query_id) | ||
self.co[query_id] = nil | ||
end | ||
|
||
function QueryAsync:QueryResume(query_id, data) | ||
local co = self.co[query_id] | ||
local status, err = coroutine.resume(co, data) | ||
if(err) then | ||
print("Error: ",status, err) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
----------------------------------------------------------------------------- | ||
-- Author: i0gan | ||
-- Email : [email protected] | ||
-- Date : 2023-09-29 | ||
-- Description: async mongo cli | ||
----------------------------------------------------------------------------- | ||
|
||
local DbProxyID = 300; | ||
Mongo = Mongo and Mongo or QueryAsync | ||
|
||
|
||
function Mongo:Bind() | ||
Net:ClientRegister(ServerType.ST_DB_PROXY, DbProxyRPC.ACK_MONGO_INSERT, self, self.AckInsert) | ||
Net:ClientRegister(ServerType.ST_DB_PROXY, DbProxyRPC.ACK_MONGO_FIND, self, self.AckFind) | ||
end | ||
|
||
function Mongo:InsertAsync(db, collection, insert_json) | ||
local query_id = self:QueryInit() | ||
local req = { | ||
query_id = query_id, | ||
db = db, | ||
collection = collection, | ||
insert_json = insert_json, | ||
} | ||
Net:SendToServer(DbProxyID, DbProxyRPC.REQ_MONGO_INSERT, Squick:Encode("rpc.ReqMongoInsert", req)) | ||
local data = self:QueryAwait(query_id) | ||
self:QueryClean(query_id) | ||
return data.code | ||
end | ||
|
||
function Mongo:AckInsert(guid, msg_data, msg_id, fd) | ||
local data = Squick:Decode("rpc.AckMongoInsert", msg_data); | ||
self:QueryResume(data.query_id, data) | ||
end | ||
|
||
function Mongo:FindAsync(db, collection, condition_json) | ||
local query_id = self:QueryInit() | ||
local req = { | ||
query_id = query_id, | ||
db = db, | ||
collection = collection, | ||
condition_json = condition_json, | ||
} | ||
Net:SendToServer(DbProxyID, DbProxyRPC.REQ_MONGO_FIND, Squick:Encode("rpc.ReqMongoFind", req)) | ||
local data = self:QueryAwait(query_id) | ||
self:QueryClean(query_id) | ||
return data.result_json | ||
end | ||
|
||
function Mongo:AckFind(guid, msg_data, msg_id, fd) | ||
local data = Squick:Decode("rpc.AckMongoFind", msg_data); | ||
print("Find ack") | ||
PrintTable(data) | ||
self:QueryResume(data.query_id, data) | ||
end | ||
|
||
Mongo:Bind() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,45 +2,54 @@ | |
-- Author: i0gan | ||
-- Email : [email protected] | ||
-- Date : 2023-09-24 | ||
-- Github: https://github.com/pwnsky/squick | ||
-- Description: async redis cli | ||
----------------------------------------------------------------------------- | ||
|
||
RedisServerID = 300; | ||
|
||
Redis = { | ||
query_id = 0; | ||
co = {} | ||
} | ||
|
||
function Blank() | ||
|
||
end | ||
local DbProxyID = 300; | ||
Redis = Redis and Redis or QueryAsync | ||
|
||
function Redis:Bind() | ||
Net:ClientRegister(ServerType.ST_DB_PROXY, DbProxyRPC.ACK_REDIS_GET, self, self.AckGet) | ||
Net:ClientRegister(ServerType.ST_DB_PROXY, DbProxyRPC.ACK_REDIS_GET, self, self.AckGetString) | ||
Net:ClientRegister(ServerType.ST_DB_PROXY, DbProxyRPC.ACK_REDIS_SET, self, self.AckSetString) | ||
end | ||
|
||
function Redis:Get(co, key) | ||
function Redis:GetStringAsync(key) | ||
local query_id = self:QueryInit() | ||
local req = { | ||
query_id = self.query_id, | ||
query_id = query_id, | ||
key = key, | ||
} | ||
self.co[self.query_id] = co; | ||
Net:SendToServer(RedisServerID, DbProxyRPC.REQ_REDIS_GET, Squick:Encode("rpc.ReqRedisGet", req), "lobby") | ||
local result = coroutine.yield() | ||
self.query_id = self.query_id + 1 % 1000000; | ||
return result.value | ||
Net:SendToServer(DbProxyID, DbProxyRPC.REQ_REDIS_GET, Squick:Encode("rpc.ReqRedisGet", req)) | ||
local data = self:QueryAwait(query_id) | ||
self:QueryClean(query_id) | ||
return data.value | ||
end | ||
|
||
function Redis:AckGet(guid, msg_data, msg_id, fd) | ||
function Redis:AckGetString(guid, msg_data, msg_id, fd) | ||
local data = Squick:Decode("rpc.AckRedisGet", msg_data); | ||
local co = self.co[data.query_id] | ||
coroutine.resume(co, data) | ||
self:QueryResume(data.query_id, data) | ||
end | ||
|
||
function Redis:SetStringAsync(key, value, ttl) | ||
local query_id = self:QueryInit() | ||
if(ttl == nil) then | ||
ttl = 0 | ||
end | ||
local req = { | ||
query_id = query_id, | ||
key = key, | ||
value = value, | ||
ttl = ttl, | ||
} | ||
Net:SendToServer(DbProxyID, DbProxyRPC.REQ_REDIS_SET, Squick:Encode("rpc.ReqRedisSet", req)) | ||
local data = self:QueryAwait(query_id) | ||
self:QueryClean(query_id) | ||
return data.code | ||
end | ||
|
||
function Redis:Set() | ||
|
||
function Redis:AckSetString(guid, msg_data, msg_id, fd) | ||
local data = Squick:Decode("rpc.AckRedisSet", msg_data); | ||
self:QueryResume(data.query_id, data) | ||
end | ||
|
||
Redis:Bind(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.