Skip to content

Commit

Permalink
Ignore invalid protocols in multi line protocol instead of program sh…
Browse files Browse the repository at this point in the history
…utdown.
  • Loading branch information
napthats committed Aug 6, 2013
1 parent d13ccfa commit 9ba370e
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions PhiVty/Protocol.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ data ServerProtocol =
Map (Char, String, [(Int, Int, Int, Int)], [((Int, Int), String)])
| NormalMessage String
| ExNotice (String, String)
| PhiList [String]
| Unfinished ServerProtocol
| Unknown String

Expand All @@ -28,7 +29,7 @@ parse u_mes ('#':protocol) =
let chara_list = case u_mes of
Nothing -> []
Just (Map (_, _, _, l)) -> l
_ -> error "Invalid server protocol." in
_ -> [] in
let (_, map_str) = splitAt 17 protocol in
let parseOption op =
((shiftR op 4) .&. 7, (shiftR op 3) .&. 1, (shiftR op 2) .&. 1, op .&. 1) in
Expand All @@ -41,15 +42,15 @@ parse u_mes ('#':protocol) =
let (dir, ma, op, chara_list) = case u_mes of
Nothing -> (' ', "", [], [])
Just (Map (d, m, o, l)) -> (d, m, o, l)
_ -> error "Invalid server protocol." in
_ -> (' ', "", [], []) in
let initial_raw = protocol !! 18 in
let initial = if ord initial_raw > 32 && ord initial_raw < 127 then initial_raw else 'A' in
let x = (read [protocol !! 12] :: Int) in
let y = (read [protocol !! 14] :: Int) in
Unfinished (Map (dir, ma, op, ((x, y), [initial]) : chara_list))
'.' ->
case u_mes of
Nothing -> error "Invalid server protocol."
Nothing -> Unknown ""
Just x -> x
_ ->
Unknown protocol
Expand Down

0 comments on commit 9ba370e

Please sign in to comment.