Skip to content

Commit

Permalink
Merge branch 'dev' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
miga97 committed Mar 11, 2022
2 parents 604aa84 + 7d92ca0 commit 594e74e
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 22 deletions.
6 changes: 4 additions & 2 deletions backend/bang/game.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,10 @@ def replay(self, log):
self.is_hidden = True
self.is_replay = True
self.replay_speed = 1
for i in range(len(log)):
print('replay:', i, 'of', len(log))
for i in range(len(log)-1):
print('replay:', i, 'of', len(log)-3, '->', log[i])
if (log[i] == "@@@"):
break
cmd = log[i].split(';')
if cmd[1] == 'players':
self.expansions = json.loads(cmd[4].replace("'",'"'))
Expand Down
30 changes: 18 additions & 12 deletions backend/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,24 @@ def get_online_players(sid):
global online_players
sio.emit('players', room='lobby', data=online_players)

@sio.event
def report(sid, text):
ses: Player = sio.get_session(sid)
data=''
if hasattr(ses, 'game'):
data = "\n".join(ses.game.rpc_log[:-1]).strip()
data = data +"\n@@@\n" +text
#print(data)
response = requests.post("https://www.toptal.com/developers/hastebin/documents", data)
key = json.loads(response.text).get('key')
if "DISCORD_WEBHOOK" in os.environ and len(os.environ['DISCORD_WEBHOOK']) > 0:
webhook = DiscordWebhook(url=os.environ['DISCORD_WEBHOOK'], content=f'New bug report, replay at https://www.toptal.com/developers/hastebin/{key}')
response = webhook.execute()
sio.emit('chat_message', room=sid, data={'color': f'green','text':f'Report OK'})
else:
print("WARNING: DISCORD_WEBHOOK not found")
print(f'New bug report, replay at https://www.toptal.com/developers/hastebin/{key}')

@sio.event
def set_username(sid, username):
ses = sio.get_session(sid)
Expand Down Expand Up @@ -337,18 +355,6 @@ def chat_message(sid, msg, pl=None):
ses.game.add_player(bot)
bot.bot_spin()
return
if '/report' in msg and not ses.game.is_replay:
data = "\n".join(ses.game.rpc_log[:-1]).strip()
response = requests.post("https://www.toptal.com/developers/hastebin/documents", data)
key = json.loads(response.text).get('key')
if "DISCORD_WEBHOOK" in os.environ and len(os.environ['DISCORD_WEBHOOK']) > 0:
webhook = DiscordWebhook(url=os.environ['DISCORD_WEBHOOK'], content=f'New bug report, replay at https://www.toptal.com/developers/hastebin/{key}')
response = webhook.execute()
sio.emit('chat_message', room=sid, data={'color': f'green','text':f'Report OK'})
else:
print("WARNING: DISCORD_WEBHOOK not found")
print(f'New bug report, replay at https://www.toptal.com/developers/hastebin/{key}')
return
if '/replay' in msg and not '/replayspeed' in msg:
_cmd = msg.split()
if len(_cmd) == 2:
Expand Down
20 changes: 18 additions & 2 deletions frontend/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
</div>
<help v-if="showHelp"/>
<div style="position:fixed;bottom:4pt;right:4pt;display:flex;">
<input type=button class="btn" style="min-width:28pt;cursor:pointer;" @click="()=>{sending_report = true}" :value=" $t('report') " />
<input type="button" class="btn" value="Discord" style="min-width:28pt;cursor:pointer;" @click="joinDiscord"/>
<input type="button" class="btn" :value="(showHelp?'X':'?')" style="min-width:28pt;border-radius:100%;cursor:pointer;" @click="getHelp"/>
<select id="theme" class="btn" v-model="theme">
Expand Down Expand Up @@ -38,22 +39,28 @@
<button @click="showUpdateUI = false">Cancel</button>
</div>
</div>
<transition name="bounce">
<full-screen-input v-if="sending_report" :defaultValue="''" :text="$t('report_bug')" :val="report" :cancel="cancelReport" :send="sendReport" :canCancel="true"/>
</transition>
</div>
</template>

<script>
import FullScreenInput from './components/FullScreenInput.vue'
import Help from './components/Help.vue';
// import Vue from 'vue'
export default {
components: { Help },
components: { Help, FullScreenInput },
name: 'App',
data: () => ({
isConnected: false,
c: false,
showUpdateUI: false,
showHelp:false,
theme: 'light',
report: '',
sending_report: false,
}),
computed: {
},
Expand Down Expand Up @@ -99,7 +106,16 @@ export default {
},
joinDiscord() {
window.open('https://discord.gg/Dr58dZ2na8', '_blank');
}
},
cancelReport(){
this.sending_report = false
},
sendReport(text){
if (text.trim().length > 0){
this.sending_report = false
this.$socket.emit('report', text)
}
},
},
watch: {
theme() {
Expand Down
27 changes: 22 additions & 5 deletions frontend/src/components/FullScreenInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
<input v-model="val" class="chooserInput"/>
</form>
<p v-if="hintText">{{hintText}}</p>
<div style="margin-top:6pt;" class="button center-stuff" v-if="showCancelBtn && val" @click="cancel(val)"><span>{{realCancelText}}</span></div>
<div class="center-stuff">
<div style="margin-top:6pt;margin-right:6pt;" class="button center-stuff" v-if="canCancel" @click="cancel()"><span>{{realCancelText}}</span></div>
<div style="margin-top:6pt;margin-left:6pt;" class="button center-stuff" v-if="showSendBtn && val" @click="send(val)"><span>{{realSendText}}</span></div>
</div>
</div>
</template>

Expand All @@ -14,37 +17,51 @@ export default {
name: 'FullScreenInput',
props: {
cancel: Function,
send: Function,
defaultValue: String,
cancelText: {
type: String,
default: '',
},
sendText: {
type: String,
default: '',
},
text: String,
hintText: String,
canCancel: {
type: Boolean,
default: false,
},
},
data: () => ({
val: '',
realCancelText: ''
realCancelText: '',
realSendText: ''
}),
computed: {
showCancelBtn() {
if (this.cancel)
showSendBtn() {
if (this.send)
return true
return false
}
},
methods: {
submit(e) {
e.preventDefault();
this.cancel(this.val);
this.send(this.val);
}
},
mounted() {
this.realCancelText = this.cancelText
this.realSendText = this.sendText
this.val = this.defaultValue
if (this.realCancelText == '') {
this.realCancelText = this.$t('cancel')
}
if (this.realSendText == '') {
this.realSendText = this.$t('send')
}
},
}
</script>
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/Lobby.vue
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
<Chooser v-show="hasToChoose" :text="`${$t('choose_card')}${target_p?$t('choose_card_from') + target_p:''}`" :cards="chooseCards" :select="chooseCard"/>
</transition>
<transition name="bounce">
<full-screen-input v-if="!started && hasToSetUsername" :defaultValue="storedUsername" :text="$t('choose_username')" :val="username" :cancel="setUsername" :cancelText="$t('ok')"/>
<full-screen-input v-if="!started && hasToSetUsername" :defaultValue="storedUsername" :text="$t('choose_username')" :val="username" :send="setUsername" :sendText="$t('ok')"/>
</transition>
</div>
</template>
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
"tip_8": "If you disconnect during in an ongoing game you will be replaced by a bot (while you are gone)!",
"online_players": "Online players: ",
"choose_username": "Pick an username:",
"report_bug":"Write what the bug consists of",
"report":"Report a bug",
"available_lobbies": "Available Lobbies:",
"spectate_lobbies": "Spectate ongoing games:",
"no_lobby_available": "No lobbies available",
Expand All @@ -26,6 +28,7 @@
"you": "YOU",
"owner": "OWNER",
"cancel": "CANCEL",
"send": "SEND",
"password": "Password: ",
"room_password_prompt": "Lobby Password: ",
"private_room": "Private Lobby",
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/i18n/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
"tip_8": "Se ti disconnetti durante una partita verrai sostituito da un bot (durante la tua assenza)!",
"online_players": "Giocatori online: ",
"choose_username": "Scegli un username:",
"report_bug":"Scrivi in cosa consiste il bug",
"report":"Segnala un bug",
"available_lobbies": "Stanze disponibili:",
"spectate_lobbies": "Osserva le partite in corso:",
"no_lobby_available": "Nessuna stanza disponibile",
Expand All @@ -26,6 +28,7 @@
"you": "TU",
"owner": "GESTORE",
"cancel": "ANNULLA",
"send": "INVIA",
"password": "Password: ",
"room_password_prompt": "Password Stanza: ",
"private_room": "Stanza Privata",
Expand Down

0 comments on commit 594e74e

Please sign in to comment.