diff options
author | David McMackins II <contact@mcmackins.org> | 2017-04-15 16:50:28 -0500 |
---|---|---|
committer | David McMackins II <contact@mcmackins.org> | 2017-04-15 16:50:28 -0500 |
commit | fb19d0108bdb42f216d9433b3215144380187e72 (patch) | |
tree | f0f1c1a957ef67ff6d4ef1fe587f460b77dbde89 | |
parent | 888acf555172deddd8f15e216c8f3036b4fc246b (diff) |
Add SELECT
-rw-r--r-- | serverthread.lua | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/serverthread.lua b/serverthread.lua index ef5d815..a1b490e 100644 --- a/serverthread.lua +++ b/serverthread.lua @@ -26,6 +26,7 @@ local finished = false local AFFIRMATIVE = 'Y\nEND\n' local NEGATIVE = 'N\nEND\n' local ERR_ARGNUM = 'ERR ARGNUM\nEND\n' +local ERR_SYNTAX = 'ERR SYNTAX\nEND\n' Server = class() @@ -150,6 +151,26 @@ function Server:_process() end elseif line == 'MAKEROOM' then self._socks[this]:send(NEGATIVE) + elseif line:startswith('SELECT') then + line = line:split(' ') + if #line ~= 2 then + self._socks[this]:send(ERR_ARGNUM) + break + end + + local i = tonumber(line[2]) + if not i then + self._socks[this]:send(ERR_SYNTAX) + elseif self._pieces[i].team ~= this then + self._socks[this]:send(NEGATIVE) + else + self._selected = self._pieces[i] + self._socks[this]:send(AFFIRMATIVE) + + for _,queue in ipairs(self._updatequeue) do + queue:insert('SELECTED ' .. i) + end + end else self._socks[this]:send('ERR COMMAND\nEND\n') end |