-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathsocket_handler.php
More file actions
108 lines (72 loc) · 2.07 KB
/
socket_handler.php
File metadata and controls
108 lines (72 loc) · 2.07 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<?php
//Stop Direct Access to the File
//Works only in PHP 5.0 and Up
if (get_included_files()[0] == __FILE__) {
http_response_code(403);
die('Forbidden');
}
//Stop Including This File Twice
if (defined(strtoupper(basename(__FILE__, '.php')) . '_PHP')) {
return true;
}
define(strtoupper(basename(__FILE__, '.php')) . '_PHP', true);
include_once 'main.php';
$weburl = "https://$socketurl";
$SecretKey = 'S0r3n@DEV';
//Send POST Data to web url
//Data will contain event name and event data
//Also send Header Secret Key to verify that the request is from the server
function sendUser($userId, $event, $data)
{
global $SecretKey;
global $weburl;
$weburl = 'http://147.135.254.149:3000';
$data = json_encode(['event' => $event, 'data' => $data]);
$ch = curl_init("$weburl/send/$userId");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-Type: application/json',
'SecretKey: ' . $SecretKey,
]);
$result = curl_exec($ch);
curl_close($ch);
return json_decode($result, true);
}
function sendAll($event, $data)
{
sendUser('all', $event, $data);
}
function sendChatMessage(
$userId,
$senderName,
$message,
$senderRank = 0,
$thumbnail = null,
$senderId = 0
) {
if (strtoupper($senderName) == 'SERVER') {
$senderId = null;
$thumbnail = null;
$senderName = 'SERVER';
$senderRank = 3;
}
if (!$thumbnail) {
$thumbnail = 'https://i.postimg.cc/Y90d6cqk/temp-Imageb-NTLrh.jpg';
}
if (!$senderId) {
$senderId = 0;
}
if (!$senderRank) {
$senderRank = 0;
}
sendUser($userId, 'chat message', [
'userid' => $senderId,
'rank' => $senderRank,
'displayname' => $senderName,
'thumbnail' => $thumbnail,
'message' => $message,
]);
}
?>