forked from FashionFlora/Albion-Online-Radar-QRadar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
158 lines (99 loc) · 3.37 KB
/
app.js
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
const express = require('express');
const session = require('express-session');
const bodyParser = require('body-parser');
const mysql = require('mysql');
const ejs = require('ejs');
const path = require('path');
const dotenv = require('dotenv');
const PhotonParser = require('./scripts/classes/PhotonPacketParser');
var Cap = require('cap').Cap;
var decoders = require('cap').decoders;
const WebSocket = require('ws');
const ip = require('ip');
const app = express();
BigInt.prototype.toJSON = function() { return this.toString() }
app.use(express.static(path.join(__dirname, 'views')));
app.set('view engine', 'ejs');
app.get('/', (req, res) => {
const viewName = 'main/home';
res.render('layout', { mainContent: viewName});
});
app.get('/home', (req, res) => {
const viewName = 'main/home';
res.render('./layout', { mainContent: viewName});
});
app.get('/raw', (req, res) => {
const viewName = 'main/raw';
res.render('layout', { mainContent: viewName });
});
app.get('/settings', (req, res) => {
const viewName = 'main/settings';
res.render('layout', { mainContent: viewName });
});
app.get('/ignorelist', (req, res) => {
const viewName = 'main/ignorelist';
res.render('layout', { mainContent: viewName });
});
app.get('/chests', (req, res) => {
const viewName = 'main/chests';
res.render('layout', { mainContent: viewName });
});
app.get('/drawing', (req, res) => {
res.render('main/drawing');
});
app.get('/logout', (req, res) => {
req.session.destroy();
res.redirect('/');
});
app.use('/scripts', express.static(__dirname + '/scripts'))
app.use('/scripts/Handlers', express.static(__dirname + '/scripts/Handlers'))
app.use('/scripts/Drawings', express.static(__dirname + '/scripts/Drawings'))
app.use('/scripts/Utils', express.static(__dirname + '/scripts/Utils'));;
app.use('/images/Resources', express.static(__dirname + '/images/Resources'));
app.use('/images/Items', express.static(__dirname + '/images/Items'));
const port = 5001;
app.listen(port, () => {
console.log(`Server is running on http://localhost:${port}`);
});
const getActiveIP = () => {
const interfaces = ip.address();
return interfaces;
};
var c = new Cap();
var device = Cap.findDevice(getActiveIP());
const filter = 'udp and (dst port 5056 or src port 5056)';
var bufSize = 4096;
var buffer = Buffer.alloc(4096);
const manager = new PhotonParser();
var linkType = c.open(device, filter, bufSize, buffer);
c.setMinBytes && c.setMinBytes(0);
const server = new WebSocket.Server({ port: 5002, host: 'localhost'});
server.on('connection', () => {
console.log("openned");
c.on('packet', function(nbytes, trunc) {
let ret = decoders.Ethernet(buffer);
ret = decoders.IPV4(buffer, ret.offset);
ret = decoders.UDP(buffer, ret.offset);
let payload = buffer.slice(ret.offset, nbytes);
// Parse the UDP payload
try
{
manager.handle(payload);
}
catch{
}
});
manager.on('event', (dictonary) => {
const dictionaryDataJSON = JSON.stringify(dictonary);
server.clients.forEach(function(client) {
client.send(JSON.stringify({ code : "event", dictionary: dictionaryDataJSON }))
});
});
manager.on('request', (dictonary) => {
const dictionaryDataJSON = JSON.stringify(dictonary);
server.clients.forEach(function(client) {
client.send(JSON.stringify({ code : "request", dictionary: dictionaryDataJSON }))
});
});
});