improved admin tools
This commit is contained in:
parent
4d48a4bd69
commit
8d90935e7d
@ -178,6 +178,7 @@ class Game:
|
||||
{'cmd':'/getcard', 'help':'Get a brand new card - sample /getcard Birra'},
|
||||
{'cmd':'/meinfo', 'help':'Get player data'},
|
||||
{'cmd':'/gameinfo', 'help':'Get game data'},
|
||||
{'cmd':'/playerinfo', 'help':'Get player data - sample /playerinfo player'},
|
||||
{'cmd':'/mebot', 'help':'Toggles bot mode'},
|
||||
{'cmd':'/getnuggets', 'help':'Adds nuggets to yourself - sample /getnuggets 5'},
|
||||
{'cmd':'/startwithseed', 'help':'start the game with custom seed'}]
|
||||
|
@ -38,6 +38,9 @@ class PendingAction(IntEnum):
|
||||
|
||||
class Player:
|
||||
|
||||
def is_admin(self):
|
||||
return self.discord_id in {'244893980960096266'}
|
||||
|
||||
def get_avatar(self):
|
||||
import requests
|
||||
headers = {
|
||||
@ -49,6 +52,9 @@ class Player:
|
||||
self.avatar = f'https://cdn.discordapp.com/avatars/{res["id"]}/{res["avatar"]}.png'
|
||||
self.sio.emit('chat_message', room=self.game.name, data=f'_change_username|{self.name}|{res["username"]}')
|
||||
self.name = res['username']
|
||||
self.discord_id = res['id']
|
||||
if self.is_admin():
|
||||
self.sio.emit('chat_message', room=self.sid, data={'color':'green', 'text':'(you are admin)'})
|
||||
if self.game:
|
||||
self.game.notify_room()
|
||||
self.sio.emit('me', data=self.name, room=self.sid)
|
||||
@ -64,6 +70,7 @@ class Player:
|
||||
self.sio = sio
|
||||
self.is_bot = bot
|
||||
self.discord_token = discord_token
|
||||
self.discord_id = None
|
||||
self.avatar = ''
|
||||
if self.is_bot:
|
||||
self.avatar = robot_pictures[randrange(len(robot_pictures))]
|
||||
|
@ -88,7 +88,8 @@ def report(sid, text):
|
||||
def set_username(sid, username):
|
||||
ses = sio.get_session(sid)
|
||||
if not isinstance(ses, Player):
|
||||
sio.save_session(sid, Player(username["name"], sid, sio, discord_token=username["discord_token"]))
|
||||
dt = username["discord_token"] if 'discord_token' in username else None
|
||||
sio.save_session(sid, Player(username["name"], sid, sio, discord_token=dt))
|
||||
print(f'{sid} is now {username}')
|
||||
advertise_lobbies()
|
||||
elif ses.game == None or not ses.game.started:
|
||||
@ -110,7 +111,8 @@ def get_me(sid, room):
|
||||
if sio.get_session(sid).game:
|
||||
sio.get_session(sid).game.notify_room()
|
||||
else:
|
||||
sio.save_session(sid, Player('player', sid, sio, discord_token=room['discord_token']))
|
||||
dt = room["discord_token"] if 'discord_token' in room else None
|
||||
sio.save_session(sid, Player('player', sid, sio, discord_token=dt))
|
||||
de_games = [g for g in games if g.name == room['name']]
|
||||
if len(de_games) == 1 and not de_games[0].started:
|
||||
join_room(sid, room)
|
||||
@ -236,7 +238,7 @@ Sockets for the status page
|
||||
|
||||
@sio.event
|
||||
def get_all_rooms(sid, deploy_key):
|
||||
if 'DEPLOY_KEY' in os.environ and deploy_key == os.environ['DEPLOY_KEY']:
|
||||
if ('DEPLOY_KEY' in os.environ and deploy_key == os.environ['DEPLOY_KEY']) or sio.get_session(sid).is_admin():
|
||||
sio.emit('all_rooms', room=sid, data=[{
|
||||
'name': g.name,
|
||||
'hidden': g.is_hidden,
|
||||
@ -252,12 +254,12 @@ def get_all_rooms(sid, deploy_key):
|
||||
|
||||
@sio.event
|
||||
def kick(sid, data):
|
||||
if 'DEPLOY_KEY' in os.environ and data['key'] == os.environ['DEPLOY_KEY']:
|
||||
if ('DEPLOY_KEY' in os.environ and data['key'] == os.environ['DEPLOY_KEY']) or sio.get_session(sid).is_admin():
|
||||
sio.emit('kicked', room=data['sid'])
|
||||
|
||||
@sio.event
|
||||
def hide_toogle(sid, data):
|
||||
if 'DEPLOY_KEY' in os.environ and data['key'] == os.environ['DEPLOY_KEY']:
|
||||
if ('DEPLOY_KEY' in os.environ and data['key'] == os.environ['DEPLOY_KEY']) or sio.get_session(sid).is_admin():
|
||||
game = [g for g in games if g.name==data['room']]
|
||||
if len(games) > 0:
|
||||
game[0].is_hidden = not game[0].is_hidden
|
||||
@ -405,13 +407,13 @@ def chat_message(sid, msg, pl=None):
|
||||
if len(cmd) == 2 and 'DEPLOY_KEY' in os.environ and cmd[1] == os.environ['DEPLOY_KEY']: # solo chi ha la deploy key può attivare la modalità debug
|
||||
ses.game.debug = not ses.game.debug
|
||||
ses.game.notify_room()
|
||||
elif ses == ses.game.players[0]: # solo l'owner può attivare la modalità debug
|
||||
elif ses == ses.game.players[0] or ses.is_admin(): # solo l'owner può attivare la modalità debug
|
||||
ses.game.debug = not ses.game.debug
|
||||
ses.game.notify_room()
|
||||
if ses.game.debug:
|
||||
sio.emit('chat_message', room=sid, data={'color': f'red','text':f'debug mode is now active, only the owner of the room can disable it with /debug'})
|
||||
return
|
||||
if not ses.game.debug:
|
||||
if not ses.game.debug and not ses.is_admin():
|
||||
sio.emit('chat_message', room=sid, data={'color': f'','text':f'debug mode is not active, only the owner of the room can enable it with /debug'})
|
||||
elif '/set_chars' in msg and not ses.game.started:
|
||||
cmd = msg.split()
|
||||
@ -539,9 +541,15 @@ def chat_message(sid, msg, pl=None):
|
||||
ses.gold_nuggets += int(cmd[1])
|
||||
ses.notify_self()
|
||||
elif '/gameinfo' in msg:
|
||||
sio.emit('chat_message', room=sid, data={'color': f'','text':f'info: {dict(filter(lambda x:x[0] != "rpc_log",ses.game.__dict__.items()))}'})
|
||||
sio.emit('chat_message', room=sid, data={'color': f'', 'text':json.dumps(ses.game.__dict__, default=lambda o: f'<{o.__class__.__name__}() not serializable>'), 'type': 'json'})
|
||||
elif '/status' in msg and ses.is_admin():
|
||||
sio.emit('mount_status', room=sid)
|
||||
elif '/meinfo' in msg:
|
||||
sio.emit('chat_message', room=sid, data={'color': f'','text':f'info: {ses.__dict__}'})
|
||||
sio.emit('chat_message', room=sid, data={'color': f'', 'text':json.dumps(ses.__dict__, default=lambda o: f'<{o.__class__.__name__}() not serializable>'), 'type': 'json'})
|
||||
elif '/playerinfo' in msg:
|
||||
cmd = msg.split()
|
||||
if len(cmd) == 2:
|
||||
sio.emit('chat_message', room=sid, data={'color': f'', 'text':json.dumps(ses.game.get_player_named(cmd[1]).__dict__, default=lambda o: f'<{o.__class__.__name__}() not serializable>'), 'type': 'json'})
|
||||
elif '/mebot' in msg:
|
||||
ses.is_bot = not ses.is_bot
|
||||
if (ses.is_bot):
|
||||
|
@ -17,6 +17,7 @@
|
||||
"vue": "^2.6.14",
|
||||
"vue-clipboard2": "^0.3.3",
|
||||
"vue-i18n": "^8.27.1",
|
||||
"vue-json-viewer": "^2.2.22",
|
||||
"vue-router": "^3.5.3",
|
||||
"vue-socket.io": "^3.0.10"
|
||||
},
|
||||
|
@ -135,6 +135,7 @@ export default {
|
||||
this.$i18n.locale = userLang.split('-')[0]
|
||||
}
|
||||
this.detectColorScheme()
|
||||
if (window.location.origin.indexOf('localhost') !== -1) return;
|
||||
datadogRum.init({
|
||||
applicationId: '076b1a5e-16a9-44eb-b320-27afd32c57a5',
|
||||
clientToken: 'pub1cc4d0d6ea0a7235aa1eab86e7a192d4',
|
||||
|
@ -9,7 +9,10 @@
|
||||
</div>
|
||||
<div class="cont">
|
||||
<transition-group name="message" tag="div" id="chatbox" :style="`${collapsed?'display:none':''}`">
|
||||
<p style="margin:1pt;" class="chat-message" v-for="(msg, i) in messages" v-bind:key="`${i}-c`" :style="`color:${msg.color};background:${msg.bgcolor}${msg.bgcolor?';border-left: medium solid '+msg.color+';padding-left:2pt;':''}`">{{msg.text}}</p>
|
||||
<p style="margin:1pt;" class="chat-message" v-for="(msg, i) in messages" v-bind:key="`${i}-c`" :style="`color:${msg.color};background:${msg.bgcolor}${msg.bgcolor?';border-left: medium solid '+msg.color+';padding-left:2pt;':''}`">
|
||||
<JsonViewer v-if="msg.type == 'json'" :value="msg.json"/>
|
||||
<span v-else>{{msg.text}}</span>
|
||||
</p>
|
||||
<p class="end" key="end" style="color:#0000">.</p>
|
||||
</transition-group>
|
||||
<div v-if="commandSuggestion.length > 0">
|
||||
@ -35,11 +38,16 @@ import prison_sfx from '@/assets/sounds/prison.mp3'
|
||||
import turn_sfx from '@/assets/sounds/turn.mp3'
|
||||
import death_sfx from '@/assets/sounds/death.mp3'
|
||||
import cash_sfx from '@/assets/sounds/cash.mp3'
|
||||
import JsonViewer from 'vue-json-viewer'
|
||||
|
||||
export default {
|
||||
name: 'Chat',
|
||||
props: {
|
||||
username: String
|
||||
},
|
||||
components: {
|
||||
JsonViewer
|
||||
},
|
||||
data: () => ({
|
||||
messages: [],
|
||||
toasts: [],
|
||||
@ -59,7 +67,6 @@ export default {
|
||||
},
|
||||
sockets: {
|
||||
chat_message(msg) {
|
||||
// console.log(msg)
|
||||
if ((typeof msg === "string" && msg.indexOf('_') === 0) || (msg.color != null && msg.text.indexOf('_') === 0)) {
|
||||
let t_color = null
|
||||
let bg_color = null
|
||||
@ -107,6 +114,9 @@ export default {
|
||||
} else { // a chat message
|
||||
(new Audio(message_sfx)).play();
|
||||
this.messages.push(msg);
|
||||
if (msg.type && msg.type === 'json') {
|
||||
msg.json = JSON.parse(msg.text);
|
||||
}
|
||||
if (this.collapsed || window.innerWidth < 1000) {
|
||||
this.toasts.push(msg);
|
||||
setTimeout(() => this.toasts.shift(), 5000);
|
||||
|
@ -85,6 +85,12 @@
|
||||
<transition name="bounce">
|
||||
<full-screen-input v-if="!started && hasToSetUsername" :defaultValue="storedUsername" :text="$t('choose_username')" :val="username" :send="setUsername" :sendText="$t('ok')"/>
|
||||
</transition>
|
||||
<transition name="bounce">
|
||||
<div v-if="displayAdminStatus" style="position:absolute;width:100%;height:100%;overflow:auto;background:#000000bf;">
|
||||
<input type="button" @click="displayAdminStatus = false" value="close"/>
|
||||
<Status deploy_key="ok"/>
|
||||
</div>
|
||||
</transition>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@ -98,6 +104,7 @@ import Player from './Player.vue'
|
||||
import Deck from './Deck.vue'
|
||||
import TinyHand from './TinyHand.vue'
|
||||
import FullScreenInput from './FullScreenInput.vue'
|
||||
import Status from './Status.vue'
|
||||
|
||||
export default {
|
||||
name: 'Lobby',
|
||||
@ -109,7 +116,8 @@ export default {
|
||||
Deck,
|
||||
TinyHand,
|
||||
PrettyCheck,
|
||||
FullScreenInput
|
||||
FullScreenInput,
|
||||
Status
|
||||
},
|
||||
data: () => ({
|
||||
username: '',
|
||||
@ -134,6 +142,7 @@ export default {
|
||||
debug_mode: false,
|
||||
showTurnFlow: false,
|
||||
turnReversed: false,
|
||||
displayAdminStatus: false,
|
||||
turn: -1,
|
||||
}),
|
||||
sockets: {
|
||||
@ -180,6 +189,9 @@ export default {
|
||||
this.username = username
|
||||
// this.$socket.emit('get_cards', 'dodge_city')
|
||||
},
|
||||
mount_status() {
|
||||
this.displayAdminStatus = true
|
||||
},
|
||||
// cards_info(data) {
|
||||
// data = JSON.parse(data)
|
||||
// let bigthing = {}
|
||||
|
@ -31,9 +31,15 @@
|
||||
</template>
|
||||
<script>
|
||||
export default {
|
||||
name: 'Help',
|
||||
name: 'Status',
|
||||
components: {
|
||||
},
|
||||
props: {
|
||||
onpage: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
}
|
||||
},
|
||||
data:()=>({
|
||||
rooms: [],
|
||||
deploy_key: ''
|
||||
@ -46,7 +52,7 @@ export default {
|
||||
},
|
||||
},
|
||||
mounted() {
|
||||
if (this.deploy_key == "")
|
||||
if (this.deploy_key == "" && this.onpage)
|
||||
this.deploy_key = prompt('Write the key');
|
||||
this.refresh();
|
||||
},
|
||||
|
14104
frontend/yarn.lock
14104
frontend/yarn.lock
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user