diff options
-rw-r--r-- | server-beta/main.lua | 2 | ||||
-rw-r--r-- | server-beta/src/pub/brave.lua | 15 | ||||
-rw-r--r-- | server-beta/src/pub/init.lua | 1 | ||||
-rw-r--r-- | server-beta/src/pub/pub.lua | 48 | ||||
-rw-r--r-- | server-beta/src/pub/taskpad.lua | 15 | ||||
-rw-r--r-- | server-beta/src/pub/waiter.lua | 15 | ||||
-rw-r--r-- | server-beta/src/service.lua | 14 |
7 files changed, 110 insertions, 0 deletions
diff --git a/server-beta/main.lua b/server-beta/main.lua index 61d66c63..79af5014 100644 --- a/server-beta/main.lua +++ b/server-beta/main.lua @@ -14,3 +14,5 @@ log.debug('ROOT:', ROOT:string()) ac = {} xpcall(dofile, log.debug, rootPath .. '/debugger.lua') +local service = require 'service' +service:start() diff --git a/server-beta/src/pub/brave.lua b/server-beta/src/pub/brave.lua new file mode 100644 index 00000000..3cfa3e40 --- /dev/null +++ b/server-beta/src/pub/brave.lua @@ -0,0 +1,15 @@ +local thread = require 'bee.thread' + +---@class pub_brave +local mt = {} +mt.__index = mt +mt.type = 'pub.brave' + +return function (name) + log.info('Create pub brave:', name) + thread.newchannel(name) + local brave = setmetatable({ + channel = thread.channel(name), + }, mt) + return brave +end diff --git a/server-beta/src/pub/init.lua b/server-beta/src/pub/init.lua new file mode 100644 index 00000000..f15aa69e --- /dev/null +++ b/server-beta/src/pub/init.lua @@ -0,0 +1 @@ +return require 'pub.pub' diff --git a/server-beta/src/pub/pub.lua b/server-beta/src/pub/pub.lua new file mode 100644 index 00000000..6df8bb0b --- /dev/null +++ b/server-beta/src/pub/pub.lua @@ -0,0 +1,48 @@ +local thread = require 'bee.thread' +local taskpad = require 'pub.taskpad' +local waiter = require 'pub.waiter' +local brave = require 'pub.brave' + +---@class pub +local m = {} +m.type = 'pub' +m.waiters = {} +m.taskPads = {} +m.braves = {} + +--- 创建公告板,空闲的勇者会从公告板上领取任务 +function m:createTaskPads(num) + for _ = 1, num do + local n = #self.taskPads + 1 + self.taskPads[n] = taskpad('task' .. n) + end +end + +--- 雇佣看板娘,完成任务的勇者会到看板娘处交付任务 +function m:hireWaiters(num) + for _ = 1, num do + local n = #self.waiters + 1 + self.waiters[n] = waiter('waiter' .. n) + end +end + +--- 招募勇者,勇者会从公告板上领取任务,完成任务后到看板娘处交付任务 +function m:recruitBraves(num) + for _ = 1, num do + local n = #self.braves + 1 + self.braves[n] = brave('brave' .. n) + end +end + +function m:build() + thread.newchannel 'task0' + thread.newchannel 'bulletin' + thread.newchannel 'log' + + self.taskPads[0] = taskpad 'task0' + self.waiters[0] = waiter 'waiter0' + self.bulletin = thread.channel 'bulletin' + self.log = thread.channel 'log' +end + +return m diff --git a/server-beta/src/pub/taskpad.lua b/server-beta/src/pub/taskpad.lua new file mode 100644 index 00000000..4690fc2c --- /dev/null +++ b/server-beta/src/pub/taskpad.lua @@ -0,0 +1,15 @@ +local thread = require 'bee.thread' + +---@class pub_taskpad +local mt = {} +mt.__index = mt +mt.type = 'pub.taskpad' + +return function (name) + log.info('Create pub task pad:', name) + thread.newchannel(name) + local taskpad = setmetatable({ + channel = thread.channel(name), + }, mt) + return taskpad +end diff --git a/server-beta/src/pub/waiter.lua b/server-beta/src/pub/waiter.lua new file mode 100644 index 00000000..82decbab --- /dev/null +++ b/server-beta/src/pub/waiter.lua @@ -0,0 +1,15 @@ +local thread = require 'bee.thread' + +---@class pub_waiter +local mt = {} +mt.__index = mt +mt.type = 'pub.waiter' + +return function (name) + log.info('Create pub waiter:', name) + thread.newchannel(name) + local waiter = setmetatable({ + channel = thread.channel(name), + }, mt) + return waiter +end diff --git a/server-beta/src/service.lua b/server-beta/src/service.lua new file mode 100644 index 00000000..2cd9c940 --- /dev/null +++ b/server-beta/src/service.lua @@ -0,0 +1,14 @@ +local pub = require 'pub' +local thread = require 'bee.thread' + +local m = {} +m.type = 'service' + +function m:start() + pub:build() + pub:createTaskPads(4) + pub:hireWaiters(4) + pub:recruitBraves(4) +end + +return m |