mirror of
https://github.com/asphyxia-core/plugin-template.git
synced 2026-03-21 17:24:33 -05:00
60 lines
1.9 KiB
TypeScript
60 lines
1.9 KiB
TypeScript
/*
|
||
EamusePluginRoute. Handle your game message like this
|
||
|
||
You can send a plain XML request to test this route:
|
||
<call model="NULL:example">
|
||
<example method="method" card="E0040123456789AB"></example>
|
||
</call>
|
||
*/
|
||
export const example: EPR = async (info, data, send) => {
|
||
/* [Check documentation for the entire API] */
|
||
|
||
/*
|
||
Access data from request like this
|
||
NOTE: all card number will be automatically converted to refid|dataid.
|
||
This is to support older game that doesn't use cardmng,
|
||
yet still allow them to register with internal profile manager.
|
||
And they can show up in WebUI as a profile, along with card binding feature.
|
||
*/
|
||
const ids = $(data).attr().card.split('|');
|
||
const refid = ids[0];
|
||
const dataid = ids[1];
|
||
|
||
/* Access config like this */
|
||
const event = U.GetConfig('event');
|
||
|
||
/*
|
||
Create user data in profile space if not exists
|
||
WebUI will try to find a "name" field in profile documents and display them.
|
||
If you are using a collection of data for each profile,
|
||
make sure to avoid using name field in supplementary documents.
|
||
If you have multiple documents per refid, it is recommended to provide a field to
|
||
simulate collections in NoSQL database (e.g. MongoDB)
|
||
*/
|
||
await DB.Upsert(
|
||
refid,
|
||
{
|
||
collection: 'profile',
|
||
name: 'PLAYER',
|
||
},
|
||
{ $inc: { login_count: 1 } }
|
||
);
|
||
|
||
/*
|
||
Send your response like this
|
||
There are more methods for sending request.
|
||
*/
|
||
send.pugFile('templates/example.pug', { refid, event, datid: dataid });
|
||
|
||
/* Or you can send ejs template (plain xml works as well) */
|
||
// send.xmlFile('templates/example.xml', { refid, event });
|
||
};
|
||
|
||
export const changeName = async (data: any) => {
|
||
await DB.Update(data.refid, { collection: 'profile' }, { $set: { name: data.name } });
|
||
};
|
||
|
||
export const randomNumber = async (data: any, send: WebUISend) => {
|
||
send.json({ number: Math.floor(Math.random() * 100) });
|
||
};
|