'/rnd' command. Pass it a (possibly empty) list of items.
authorunc0rr
Wed, 22 May 2013 00:49:37 +0400
changeset 9035 e84d42a4311c
parent 9034 279168729cc3
child 9037 d1478ce0f298
'/rnd' command. Pass it a (possibly empty) list of items.
gameServer/Actions.hs
gameServer/CoreTypes.hs
gameServer/HWProtoCore.hs
gameServer/HWProtoInRoomState.hs
gameServer/HWProtoLobbyState.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
--- 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]
 
--- 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
--- 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)
 
--- 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 --