equal
deleted
inserted
replaced
1 {- |
1 {- |
2 * Hedgewars, a free turn based strategy game |
2 * Hedgewars, a free turn based strategy game |
3 * Copyright (c) 2004-2014 Andrey Korotaev <unC0Rr@gmail.com> |
3 * Copyright (c) 2004-2015 Andrey Korotaev <unC0Rr@gmail.com> |
4 * |
4 * |
5 * This program is free software; you can redistribute it and/or modify |
5 * This program is free software; you can redistribute it and/or modify |
6 * it under the terms of the GNU General Public License as published by |
6 * it under the terms of the GNU General Public License as published by |
7 * the Free Software Foundation; version 2 of the License |
7 * the Free Software Foundation; version 2 of the License |
8 * |
8 * |
48 if pingsQueue cl == 0 then |
48 if pingsQueue cl == 0 then |
49 return [ProtocolError "Protocol violation"] |
49 return [ProtocolError "Protocol violation"] |
50 else |
50 else |
51 return [ModifyClient (\c -> c{pingsQueue = pingsQueue c - 1})] |
51 return [ModifyClient (\c -> c{pingsQueue = pingsQueue c - 1})] |
52 |
52 |
53 handleCmd ["CMD", parameters] = uncurry h $ extractParameters parameters |
53 handleCmd cmd = do |
|
54 (ci, irnc) <- ask |
|
55 let cl = irnc `client` ci |
|
56 if logonPassed cl then |
|
57 if isChecker cl then |
|
58 handleCmd_checker cmd |
|
59 else |
|
60 handleCmd_loggedin cmd |
|
61 else |
|
62 handleCmd_NotEntered cmd |
|
63 |
|
64 |
|
65 handleCmd_loggedin ["CMD", parameters] = uncurry h $ extractParameters parameters |
54 where |
66 where |
55 h "DELEGATE" n | not $ B.null n = handleCmd ["DELEGATE", n] |
67 h "DELEGATE" n | not $ B.null n = handleCmd ["DELEGATE", n] |
56 h "SAVEROOM" n | not $ B.null n = handleCmd ["SAVEROOM", n] |
68 h "SAVEROOM" n | not $ B.null n = handleCmd ["SAVEROOM", n] |
57 h "LOADROOM" n | not $ B.null n = handleCmd ["LOADROOM", n] |
69 h "LOADROOM" n | not $ B.null n = handleCmd ["LOADROOM", n] |
58 h "SAVE" n | not $ B.null n = handleCmd ["SAVE", n] |
70 h "SAVE" n | not $ B.null n = handleCmd ["SAVE", n] |
81 h "INFO" n | not $ B.null n = handleCmd ["INFO", n] |
93 h "INFO" n | not $ B.null n = handleCmd ["INFO", n] |
82 h "RESTART_SERVER" "YES" = handleCmd ["RESTART_SERVER"] |
94 h "RESTART_SERVER" "YES" = handleCmd ["RESTART_SERVER"] |
83 h c p = return [Warning $ B.concat ["Unknown cmd: /", c, " ", p]] |
95 h c p = return [Warning $ B.concat ["Unknown cmd: /", c, " ", p]] |
84 |
96 |
85 extractParameters p = let (a, b) = B.break (== ' ') p in (upperCase a, B.dropWhile (== ' ') b) |
97 extractParameters p = let (a, b) = B.break (== ' ') p in (upperCase a, B.dropWhile (== ' ') b) |
86 |
|
87 |
|
88 handleCmd cmd = do |
|
89 (ci, irnc) <- ask |
|
90 let cl = irnc `client` ci |
|
91 if logonPassed cl then |
|
92 if isChecker cl then |
|
93 handleCmd_checker cmd |
|
94 else |
|
95 handleCmd_loggedin cmd |
|
96 else |
|
97 handleCmd_NotEntered cmd |
|
98 |
|
99 |
98 |
100 handleCmd_loggedin ["INFO", asknick] = do |
99 handleCmd_loggedin ["INFO", asknick] = do |
101 (_, rnc) <- ask |
100 (_, rnc) <- ask |
102 maybeClientId <- clientByNick asknick |
101 maybeClientId <- clientByNick asknick |
103 isAdminAsking <- liftM isAdministrator thisClient |
102 isAdminAsking <- liftM isAdministrator thisClient |