增加几个常用的向游戏服发送消息的方法
This commit is contained in:
parent
662ec2fbea
commit
0252c39e18
66
src/services/WsSvr.ts
Normal file
66
src/services/WsSvr.ts
Normal file
@ -0,0 +1,66 @@
|
||||
import axios from 'axios'
|
||||
|
||||
|
||||
const apiBase = 'http://127.0.0.1:2567/api'
|
||||
/**
|
||||
* 发送私信给玩家
|
||||
* @param roomId
|
||||
* @param clientId
|
||||
* @param type
|
||||
* @param msg
|
||||
* @return {Promise<AxiosResponse<any>>}
|
||||
*/
|
||||
export async function sendMsg(roomId, clientId, type, msg) {
|
||||
const url = `${apiBase}/room/call`
|
||||
const args = [clientId, type, msg]
|
||||
const data = {
|
||||
roomId,
|
||||
method: 'smsg',
|
||||
args: JSON.stringify(args)
|
||||
}
|
||||
return axios.get(url, {params: data})
|
||||
.then(res => {
|
||||
return res.data
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送广播消息
|
||||
* @param roomId
|
||||
* @param type
|
||||
* @param msg
|
||||
* @return {Promise<AxiosResponse<any>>}
|
||||
*/
|
||||
export async function broadcast(roomId, type, msg) {
|
||||
const url = `${apiBase}/broadcast`
|
||||
const data = {
|
||||
roomId,
|
||||
type,
|
||||
msg
|
||||
}
|
||||
return axios.get(url, {params: data})
|
||||
.then(res => {
|
||||
return res.data
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 从房间踢掉玩家
|
||||
* @param roomId
|
||||
* @param clientId
|
||||
* @return {Promise<AxiosResponse<any>>}
|
||||
*/
|
||||
export async function kickClient(roomId, clientId) {
|
||||
const url = `${apiBase}/room/call`
|
||||
const args = [clientId]
|
||||
const data = {
|
||||
roomId,
|
||||
method: '_forceClientDisconnect',
|
||||
args: JSON.stringify(args)
|
||||
}
|
||||
return axios.get(url, {params: data})
|
||||
.then(res => {
|
||||
return res.data
|
||||
})
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user