616eab717631788ab55e494978c27a992b98fc25
[ga4php.git] / authserver / authd / authd.php
1 <?php
2
3 if(file_exists("config.php")) {
4         require_once("config.php");
5 } else {
6         // config file doesnt exist, we must abort sensibly
7 }
8
9 // get out master library for ga4php
10 require_once("../lib/lib.php");
11
12         
13 //exit(0);
14 // first we want to fork into the background like all good daemons should
15 //$pid = pcntl_fork();
16 $pid = 0;
17
18 if($pid == -1) {
19         
20 } else if($pid) {
21         // i am the parent, i shall leave
22         echo "i am a parent, i leave\n";
23         exit(0);
24 } else {
25         
26         
27         /// ok, this is just testing stuff... create queue
28         global $MSG_QUEUE_KEY_ID_SERVER, $MSG_QUEUE_KEY_ID_CLIENT;
29         
30         
31         
32         $cl_queue = msg_get_queue($MSG_QUEUE_KEY_ID_CLIENT, 0666 | 'IPC_CREAT');
33         $sr_queue = msg_get_queue($MSG_QUEUE_KEY_ID_SERVER, 0666 | 'IPC_CREAT');
34
35         $myga = new gaasGA();
36         global $myga;
37         
38         
39         print_r($myga);
40         
41         while(true) {
42                 msg_receive($sr_queue, 0, $msg_type, 16384, $msg);
43                 echo "Got message $msg_type\n";
44                 print_r($msg);
45                 switch($msg_type) {
46                         case MSG_AUTH_USER:
47                                 echo "got auth message, $msg\n";
48                                 $username = $msg["user"];
49                                 $passcode = $msg["passcode"];
50                                 global $myga;
51                                 msg_send($cl_queue, MSG_AUTH_USER, $myga->authenticateUser($username, $passcode));
52                                 break;
53                         case MSG_ADD_USER:
54                                 echo "add user\n";
55                                 $username = $msg["username"];
56                                 global $myga;
57                                 msg_send($cl_queue, MSG_ADD_USER, $myga->setUser($username));
58                                 break;
59                         case MSG_DELETE_USER:
60                                 break;
61                         default:
62                                 echo "um??\n";
63                                 
64                 }               
65                 echo "Back to wait\n";
66         }       
67 }
68
69 ?>