server.php 582 B

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. include 'functions.php';
  3. session_start();
  4. $saloon = get_post_var("saloon");
  5. $json_msgs = file_lock_and_get_json(get_msg_file_path($saloon));
  6. $from = get_post_var("from");
  7. $count_msgs = count($json_msgs['msgs']);
  8. if($from == $count_msgs)
  9. {
  10. // no new message
  11. return;
  12. }
  13. else if($from > $count_msgs)
  14. {
  15. // client has more messages -> content has been deleted
  16. $msg_to_send['reset'] = true;
  17. }
  18. $msg_to_send['last_message'] = $count_msgs;
  19. for($i = $from ; $i < $count_msgs ; ++$i)
  20. {
  21. $msg_to_send['msgs'][] = $json_msgs['msgs'][$i];
  22. }
  23. echo json_encode($msg_to_send);
  24. ?>