Advertisement
austinh115

[PHP] Connect4 Packet

Jul 11th, 2015
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.09 KB | None | 0 0
  1. if($data['i'] == 20010 && isset($data['d']) && $data['u'] != 404) {
  2. try {
  3. if($data['t'] == "") {
  4. if(isset($this->boards[$data['u']]))
  5. unset($this->boards[$data['u']]);// = new Connect4();
  6. return;
  7. }
  8. if((isset($this->boards[$data['u']]) && (strlen($data['t']) == 0 || strlen($data['t'] == 1))) || !isset($this->boards[$data['u']])) $this->boards[$data['u']] = new Connect4();
  9. $last = substr($data['t'], -1);
  10. if(is_numeric($last)) {
  11. return $this->sendPC($data['u'], "The fuck you doin?");
  12. }
  13. $move = $this->boards[$data['u']]->set(ord($last) - 65);
  14. //var_dump($move);
  15. if($move == 1000) {
  16. $this->sendPC($data['u'], "You have won.");
  17. unset($this->boards[$data['u']]);
  18. return;
  19. } else if ($move == 50) {
  20. $this->sendPC($data['u'], "You caused the game to become a draw.");
  21. unset($this->boards[$data['u']]);
  22. return;
  23. } else if ($move[0] == 51) {
  24. $this->sendPC($data['u'], "I caused the game to become a draw.");
  25. unset($this->boards[$data['u']]);
  26. } else if ($move == -1000 || $move[0] == -1000) {
  27. $this->sendPC($data['u'], "You have lost.");
  28. unset($this->boards[$data['u']]);
  29. } else if ($move == 666) {
  30. //$this->sendPC($data['u'], "Tsk tsk tsk... No cheating.");
  31. $this->socket->send($this->buildPacket('x', array(
  32. 'i' => 20010,
  33. 'u' => $data['d'],
  34. 'd' => $data['u'],
  35. 't' => substr($data['t'], 0, -1),
  36. )));
  37. return;
  38. } else if(strlen($data['t']) >= 42) {
  39. $this->sendPC($data['u'], "The game has ended in a draw because the board is full.");
  40. unset($this->boards[$data['u']]);
  41. return;
  42. }
  43. if(is_array($move)) {
  44. $move = $move[1];
  45. }
  46. $move = chr($move + 65);
  47. $this->socket->send($this->buildPacket('x', array(
  48. 'i' => 20010,
  49. 'u' => $data['d'],
  50. 'd' => $data['u'],
  51. 't' => $data['t'] . $move,
  52. )));
  53. } catch (Exception $e) {
  54. print $e->getMessage()."\n";
  55. }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement