import { SNetServer, BitStream, SNET_PRIORITES } from 'node-snet'
const server = new SNetServer({ port: 22822 });
server.on('ready', () => {
console.log('@server: started');
});
enum Packet {
Ping,
Pong,
SendEmoji
};
server.on('onReceivePacket', async (id, bs, ip, port) => {
switch (id) {
case Packet.Ping:
server.send(Packet.Pong, new BitStream(), SNET_PRIORITES.HIGH, ip, port);
console.log(`[PING] Pong ${ip}:${port}`);
break;
case Packet.SendEmoji:
server.sendAll(Packet.SendEmoji, bs, SNET_PRIORITES.HIGH);
console.log(`[EMOJI] Resend`);
break;
}
});
server.listen();