remove minecraft stuff

This commit is contained in:
HF 2021-06-03 23:19:21 +02:00
parent 22e6bf3139
commit 706fb2729e
3 changed files with 1 additions and 250 deletions

43
API.md
View File

@ -48,52 +48,9 @@ error is a message on error, else null.
success... self explanatory success... self explanatory
waitSeconds is the current cooldown. waitSeconds is the current cooldown.
coolDownSeconds is the added cooldown (negative if pixel couldn't be set because max cooldown got reached) coolDownSeconds is the added cooldown (negative if pixel couldn't be set because max cooldown got reached)
### Minecraft Login notification
```["login", minecraftid, minecraftname, ip]```
You will get an answer back like:
```["mcme", minecraftid, waitSeconds, pixelplanetname]```
with pixelplanetname being null/None if there is no pixelplanet account linked to this minecraftid.
wait Seconds is the cooldown like in `retpixel` above.
### Minecraft LogOut notification
```["logout", minecraftid]```
### Send Chat Message from Minecraft
```["mcchat", minecraftname, message]```
(got an extra command because minecraftname gets resolved to linked pixelplanet user if possible)
### Send Chat Message ### Send Chat Message
```["chat", name, message, country, channelId]``` ```["chat", name, message, country, channelId]```
channelId is an integer, channel 0 is `en` channel 1 is `int` and maybe more to come. channelId is an integer, channel 0 is `en` channel 1 is `int` and maybe more to come.
(messages with the name "info" will be displayed as red notifications in the chat window) (messages with the name "info" will be displayed as red notifications in the chat window)
### Link Minecraft Account to pixelplanet Account
```["linkacc", minecraftid, minecraftname, pixelplanetname]```
Immediate answer:
```["linkret", minecraftid, error]```
Error will be null/None if link request can get sent, else it will be a string with the reason why not, examples:
- "You are already verified to [name]"
- "Can not find user [name] on pixelplanet"
- "You already linked to other account [name]"
User will then be asked if he wants to link the account on pixelplanet.
Answer after accept/deny by user:
```["linkver", minecraftid, pixelplanetname, accepted]```
With accepted being either true or false. This will be sent to every client connected to the API websocket.
### Report online minecraft users
Send list of all online users in minecraft periodically (all 10 to 15min) to avoid getting out of sync.
```["userlst", [["minecraftid1", "minecraftname1"], ["minecraftid2", "minecraftname2"], ...]]```
### Minecraft TP request
If a user requests a tp in minecraft you get a message
```["mctp", "minecraftid", x, y]```

View File

@ -1,122 +0,0 @@
/*
*
* Minecraft user handling
*
* @flow
*/
import { User, RegUser } from '../data/models';
class Minecraft {
online: Object;
constructor() {
this.online = {};
}
async reportLogin(minecraftid, minecraftname) {
const user = new User();
user.minecraftname = minecraftname;
const reguser = await RegUser.findOne({ where: { minecraftid } });
if (reguser && reguser.mcVerified) {
user.setRegUser(reguser);
reguser.update({ minecraftname });
}
this.online[minecraftid] = user;
// this.updateRedisOnlineList();
return user;
}
/*
* TODO: whole online list should be handled by redis
updateRedisOnlineList() {
}
*/
reportLogout(minecraftid) {
delete this.online[minecraftid];
}
reportUserlist(list) {
this.online = {};
list.forEach((user) => {
const [minecraftid, minecraftname] = user;
this.reportLogin(minecraftid, minecraftname);
});
}
static async linkacc(minecraftid, minecraftname, name) {
try {
const finduser = await RegUser.findOne({ where: { minecraftid } });
if (finduser) {
if (finduser.name === name) {
if (finduser.mcVerified) {
return 'You are already verified';
}
// eslint-disable-next-line max-len
return 'You already got a verification message in the pixelplanet UserArea. Please refresh the page if you do not see it.';
}
return `You already linked to other account ${finduser.name}.`;
}
const reguser = await RegUser.findOne({ where: { name } });
if (reguser) {
if (reguser.minecraftid) {
// eslint-disable-next-line max-len
return `This pixelplanet account is already linked to ${reguser.minecraftname}`;
}
reguser.update({ minecraftname, minecraftid });
return null;
}
return `Can not find user ${name} on pixelplanet.`;
} catch (err) {
return 'An unexpected error occured :(';
}
}
minecraftid2User(minecraftid: string): User {
if (this.online[minecraftid]) {
return this.online[minecraftid];
}
const user = new User();
if (minecraftid) {
RegUser.findOne({ where: { minecraftid } }).then((reguser) => {
if (reguser && reguser.mcVerified) {
user.id = reguser.id;
user.minecraftname = reguser.minecraftname;
user.setRegUser(reguser);
} else {
user.minecraftname = minecraftid;
}
});
}
return user;
}
minecraftname2User(minecraftname: string): User {
const searchstring = minecraftname;
const onlineIds = Object.keys(this.online);
for (let i = 0; i < onlineIds.length; i += 1) {
const id = onlineIds[i];
const user = this.online[id];
if (user.minecraftname === searchstring) { return user; }
}
const user = new User();
user.minecraftname = searchstring;
if (minecraftname) {
RegUser.findOne({ where: { minecraftname } }).then((reguser) => {
if (reguser && reguser.mcVerified) {
user.id = reguser.id;
user.setRegUser(reguser);
// this.online[reguser.minecraftid] = user;
}
});
}
return user;
}
}
export default Minecraft;

View File

@ -14,9 +14,7 @@ import WebSocket from 'ws';
import WebSocketEvents from './WebSocketEvents'; import WebSocketEvents from './WebSocketEvents';
import webSockets from './websockets'; import webSockets from './websockets';
import { getIPFromRequest } from '../utils/ip'; import { getIPFromRequest } from '../utils/ip';
import Minecraft from '../core/minecraft';
import { setPixelByCoords } from '../core/setPixel'; import { setPixelByCoords } from '../core/setPixel';
import { drawByCoords } from '../core/draw';
import logger from '../core/logger'; import logger from '../core/logger';
import { APISOCKET_KEY } from '../core/config'; import { APISOCKET_KEY } from '../core/config';
import chatProvider from '../core/ChatProvider'; import chatProvider from '../core/ChatProvider';
@ -42,7 +40,6 @@ async function verifyClient(info, done) {
class APISocketServer extends WebSocketEvents { class APISocketServer extends WebSocketEvents {
wss: WebSocket.Server; wss: WebSocket.Server;
mc: Minecraft;
constructor() { constructor() {
super(); super();
@ -59,7 +56,6 @@ class APISocketServer extends WebSocketEvents {
verifyClient, verifyClient,
}); });
this.wss = wss; this.wss = wss;
this.mc = new Minecraft();
wss.on('error', (e) => { wss.on('error', (e) => {
logger.error(`APIWebSocket Server Error ${e.message}`); logger.error(`APIWebSocket Server Error ${e.message}`);
@ -196,79 +192,11 @@ class APISocketServer extends WebSocketEvents {
if (!minecraftid && !ip) { if (!minecraftid && !ip) {
setPixelByCoords('0', clr, x, y); setPixelByCoords('0', clr, x, y);
ws.send(JSON.stringify(['retpxl', null, null, true, 0, 0])); ws.send(JSON.stringify(['retpxl', null, null, true, 0, 0]));
return;
} }
const user = this.mc.minecraftid2User(minecraftid); // minecraftid support got removed
user.ip = ip;
const {
error, success, waitSeconds, coolDownSeconds,
} = await drawByCoords(user, '0', clr, x, y, null);
ws.send(JSON.stringify([
'retpxl',
(minecraftid) || ip,
(error) || null,
success,
waitSeconds,
(coolDownSeconds) || null,
]));
return; return;
} }
logger.info(`APISocket message ${message}`); logger.info(`APISocket message ${message}`);
if (command === 'login') {
const [minecraftid, minecraftname, ip] = packet;
const user = await this.mc.reportLogin(minecraftid, minecraftname);
// get userinfo
user.ip = ip;
const wait = await user.getWait(0);
const waitSeconds = (wait) ? wait / 1000 : null;
const name = (user.id == null) ? null : user.regUser.name;
ws.send(JSON.stringify([
'mcme',
minecraftid,
waitSeconds,
name,
]));
return;
}
if (command === 'userlst') {
const [userlist] = packet;
if (!Array.isArray(userlist) || !Array.isArray(userlist[0])) {
logger.error('Got invalid minecraft userlist on APISocketServer');
return;
}
this.mc.reportUserlist(userlist);
return;
}
if (command === 'logout') {
const [minecraftid] = packet;
this.mc.reportLogout(minecraftid);
return;
}
if (command === 'mcchat') {
const [minecraftname, msg] = packet;
const user = this.mc.minecraftname2User(minecraftname);
const chatname = (user.id)
? `[MC] ${user.regUser.name}`
: `[MC] ${minecraftname}`;
chatProvider.broadcastChatMessage(
chatname,
msg,
chatProvider.enChannelId,
chatProvider.infoUserId,
'xx',
false,
);
this.broadcastChatMessage(
chatname,
msg,
chatProvider.enChannelId,
chatProvider.infoUserId,
'xx',
true,
ws,
);
return;
}
if (command === 'chat') { if (command === 'chat') {
const [name, msg, country, channelId] = packet; const [name, msg, country, channelId] = packet;
chatProvider.broadcastChatMessage( chatProvider.broadcastChatMessage(
@ -290,18 +218,6 @@ class APISocketServer extends WebSocketEvents {
); );
return; return;
} }
if (command === 'linkacc') {
const [minecraftid, minecraftname, name] = packet;
const ret = await Minecraft.linkacc(minecraftid, minecraftname, name);
if (!ret) {
webSockets.notifyChangedMe(name);
}
ws.send(JSON.stringify([
'linkret',
minecraftid,
ret,
]));
}
} catch (err) { } catch (err) {
logger.error(`Got undecipherable api-ws message ${message}`); logger.error(`Got undecipherable api-ws message ${message}`);
} }