# HG changeset patch # User unc0rr # Date 1232909679 0 # Node ID 3aa7d21baca15e87eebd8481d807202d26c14a97 # Parent 98cf15b23985e2e5c2286f32c1b2eded6ea06d08 Add an ability for global messages when server started with password option set diff -r 98cf15b23985 -r 3aa7d21baca1 netserver/HWProto.hs --- a/netserver/HWProto.hs Sun Jan 25 18:54:30 2009 +0000 +++ b/netserver/HWProto.hs Sun Jan 25 18:54:39 2009 +0000 @@ -302,6 +302,15 @@ handleCmd_noRoom client _ _ ["CHAT_STRING", msg] = (noChangeClients, noChangeRooms, answerChatString (nick client) msg) +handleCmd_noRoom client _ _ ["GLOBALMSG", password, msg] = + (noChangeClients, noChangeRooms, [answer]) + where + answer = \serverInfo -> + if (not $ null password) && (adminPassword serverInfo == password) then + (allClients, ["CHAT_STRING", nick client, msg]) + else + (clientOnly, ["ERROR", "Wrong password"]) + handleCmd_noRoom _ _ _ _ = (noChangeClients, noChangeRooms, answerBadCmd) diff -r 98cf15b23985 -r 3aa7d21baca1 netserver/Miscutils.hs --- a/netserver/Miscutils.hs Sun Jan 25 18:54:30 2009 +0000 +++ b/netserver/Miscutils.hs Sun Jan 25 18:54:39 2009 +0000 @@ -99,6 +99,7 @@ { isDedicated :: Bool, serverMessage :: String, + adminPassword :: String, listenPort :: PortNumber, loginsNumber :: Int, lastHourUsers :: [UTCTime], @@ -109,6 +110,7 @@ ServerInfo True "
" + "" 46631 0 [] diff -r 98cf15b23985 -r 3aa7d21baca1 netserver/Opts.hs --- a/netserver/Opts.hs Sun Jan 25 18:54:30 2009 +0000 +++ b/netserver/Opts.hs Sun Jan 25 18:54:39 2009 +0000 @@ -14,10 +14,11 @@ options :: [OptDescr (ServerInfo -> ServerInfo)] options = [ Option ['p'] ["port"] (ReqArg readListenPort "PORT") "listen on PORT", - Option ['d'] ["dedicated"] (ReqArg readDedicated "BOOL") "start as dedicated (True or False)" + Option ['d'] ["dedicated"] (ReqArg readDedicated "BOOL") "start as dedicated (True or False)", + Option [] ["password"] (ReqArg readPassword "STRING") "admin password" ] -readListenPort, readDedicated :: String -> ServerInfo -> ServerInfo +readListenPort, readDedicated, readPassword :: String -> ServerInfo -> ServerInfo readListenPort str opts = opts{listenPort = readPort} where readPort = fromInteger $ fromMaybe 46631 (maybeRead str :: Maybe Integer) @@ -26,6 +27,8 @@ where readDedicated = fromMaybe True (maybeRead str :: Maybe Bool) +readPassword str opts = opts{adminPassword = str} + getOpts :: ServerInfo -> IO ServerInfo getOpts opts = do args <- getArgs