# HG changeset patch # User unc0rr # Date 1369169377 -14400 # Node ID e84d42a4311c9eb08c65b677d3260474310cb4d6 # Parent 279168729cc305a3bc030dcddf687eaddb10283d '/rnd' command. Pass it a (possibly empty) list of items. diff -r 279168729cc3 -r e84d42a4311c gameServer/Actions.hs --- a/gameServer/Actions.hs Wed May 22 00:12:15 2013 +0400 +++ b/gameServer/Actions.hs Wed May 22 00:49:37 2013 +0400 @@ -20,6 +20,7 @@ import Control.Exception import System.Process import Network.Socket +import System.Random ----------------------------- #if defined(OFFICIAL_SERVER) import OfficialServer.GameReplayStore @@ -615,6 +616,12 @@ processAction $ Warning versionsStats +processAction (Random chans items) = do + let i = if null items then ["heads", "tails"] else items + n <- io $ randomRIO (0, length i - 1) + processAction $ AnswerClients chans ["CHAT", "[random]", i !! n] + + #if defined(OFFICIAL_SERVER) processAction SaveReplay = do ri <- clientRoomA diff -r 279168729cc3 -r e84d42a4311c gameServer/CoreTypes.hs --- a/gameServer/CoreTypes.hs Wed May 22 00:12:15 2013 +0400 +++ b/gameServer/CoreTypes.hs Wed May 22 00:49:37 2013 +0400 @@ -75,6 +75,7 @@ | CheckRecord | CheckFailed B.ByteString | CheckSuccess [B.ByteString] + | Random [ClientChan] [B.ByteString] type ClientChan = Chan [B.ByteString] diff -r 279168729cc3 -r e84d42a4311c gameServer/HWProtoCore.hs --- a/gameServer/HWProtoCore.hs Wed May 22 00:12:15 2013 +0400 +++ b/gameServer/HWProtoCore.hs Wed May 22 00:49:37 2013 +0400 @@ -45,10 +45,12 @@ h ["STATS"] = handleCmd ["STATS"] h ("PART":m:ms) = handleCmd ["PART", B.unwords $ m:ms] h ("QUIT":m:ms) = handleCmd ["QUIT", B.unwords $ m:ms] + h ("RND":rs) = handleCmd ("RND":rs) h ("GLOBAL":m:ms) = do + cl <- thisClient rnc <- liftM snd ask let chans = map (sendChan . client rnc) $ allClients rnc - return [AnswerClients chans ["CHAT", "[global notice]", B.unwords $ m:ms]] + return [AnswerClients chans ["CHAT", "[global notice]", B.unwords $ m:ms] | isAdministrator cl] h c = return [Warning . B.concat . L.intersperse " " $ "Unknown cmd" : c] handleCmd cmd = do diff -r 279168729cc3 -r e84d42a4311c gameServer/HWProtoInRoomState.hs --- a/gameServer/HWProtoInRoomState.hs Wed May 22 00:12:15 2013 +0400 +++ b/gameServer/HWProtoInRoomState.hs Wed May 22 00:49:37 2013 +0400 @@ -348,6 +348,10 @@ else return [] +handleCmd_inRoom ("RND":rs) = do + n <- clientNick + s <- roomClientsChans + return [AnswerClients s ["CHAT", n, B.unwords $ "/rnd" : rs], Random s rs] handleCmd_inRoom ["LIST"] = return [] -- for old clients (<= 0.9.17) diff -r 279168729cc3 -r e84d42a4311c gameServer/HWProtoLobbyState.hs --- a/gameServer/HWProtoLobbyState.hs Wed May 22 00:12:15 2013 +0400 +++ b/gameServer/HWProtoLobbyState.hs Wed May 22 00:49:37 2013 +0400 @@ -144,6 +144,11 @@ else liftM ((:) (AnswerClients [clChan] ["JOINING", roomName])) $ handleCmd_lobby ["JOIN_ROOM", roomName] + +handleCmd_lobby ("RND":rs) = do + c <- liftM sendChan thisClient + return [Random [c] rs] + --------------------------- -- Administrator's stuff --