-
Notifications
You must be signed in to change notification settings - Fork 0
/
RabbitMQServer.php
72 lines (61 loc) · 2.03 KB
/
RabbitMQServer.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/php
<?php
require_once('path.inc');
require_once('get_host_info.inc');
require_once('rabbitMQLib.inc');
include ("account.php");
( $connect = mysql_connect ( $dbhostname, $dbusername, $dbpassword ) ) or die ( "Unable to connect to MySQL database" );
mysql_select_db( $dbproject );
function doLogin($username,$password)
{
$s = "select * from login where Username='$username' and Password='$password'";
( $t = mysql_query ( $s ) ) or die ( mysql_error() );
if ( mysql_num_rows ($t) > 0 )
return true;
else
return false;
}
function doRegister($username,$password,$email)
{
$s = "select * from login where Username='$username' or Email='$email'";
( $t = mysql_query ( $s ) ) or die ( mysql_error() );
if ( mysql_num_rows ($t) < 1 )
{
$x = "insert into login values ('$username','$password','$email')";
( $y = mysql_query ( $x ) ) or die ( mysql_error() );
return true;
}
else
return false;
}
function requestProcessor($request)
{
echo "received request".PHP_EOL;
var_dump($request);
if(!isset($request['type']))
{
return "ERROR: unsupported message type";
}
switch ($request['type'])
{
case "login":
$authentication = doLogin($request['username'],$request['password']);
if ($authentication == true)
return array("returnCode" => '0', 'message' => "Login Successful.");
else
return array("returnCode" => '1', 'message' => "Login Unsuccessful.");
case "register":
$registerUser = doRegister($request['username'],$request['password'],$request['email']);
if ($registerUser == true)
return array("returnCode" => '2', 'message' => "Register Successful.");
else
return array("returnCode" => '3', 'message' => "Register Unsuccessful.");
case "validate_session":
return doValidate($request['sessionId']);
}
//return array("returnCode" => '0', 'message'=>"Server received request and processed");
}
$server = new rabbitMQServer("RabbitMQ.ini","testServer");
$server->process_requests('requestProcessor');
exit();
?>