1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
########################################################################################
# This file is part of Spheres.
# Copyright (C) 2019 Jesusalva
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
########################################################################################
# Definitions
init python:
# FIXME: Drop dead if session_id mismatches (new "token")
# Same as ondata?
def onmsg(self, message):
global tr_load, tr_val, tr_busy
stdout("Server : " + str(message))
# Inform whatever is waiting for us that a reply was obtained
tr_load=True
tr_val=str(message)
# We do not clean tr_busy here
return
def ondata(self, msg, dtype, cont):
#print("INFO: data received\n")
"""
on_data: callback object which is called when a message received.
This is called before on_message or on_cont_message,
and then on_message or on_cont_message is called.
on_data has 4 argument.
The 1st argument is this class object.
The 2nd argument is utf-8 string which we get from the server.
The 3rd argument is data type. ABNF.OPCODE_TEXT or ABNF.OPCODE_BINARY will be came.
The 4th argument is continue flag. if 0, the data continue
"""
#renpy.notify(msg)
return
def onopen(self):
global tr_busy, tr_load, tr_val, HOST
print("Opening connection to %s" % HOST)
tr_load=True
tr_val=""
tr_busy=False
self.send("PING")
def onerror(self, err):
stdout("ERROR RECEIVED")
stdout("More details: %s" % repr(err))
stdout("An error happened: %s" % str(err))
# FIXME: If such error happen, the game never dies
# This is a huge problem o.o
while True:
renpy.call_screen("msgbox",
"An unrecoverable error happened.\nPress OK to return to main menu screen.")
#raise KeyboardException(str(err))
#raise err
# FIXME: Not working, and the loop also does not work
# Maybe because it causes an Exception?
# I wonder if I can/should run this in a non-daemon thread?
# But I sense the problem is not here but a level above
#renpy.quit(relaunch=True, status=1)
sdelay(1.0)
return 1
|