Permalink
Browse files

invites

  • Loading branch information...
cflavio committed Jul 7, 2018
1 parent d51393b commit 8c9dba4d91ac6161f047920d03a07985df244c60
@@ -3,7 +3,6 @@
from feedparser import parse
# from keyring_jeepney import Keyring
from panda3d.core import TextNode
from igdc import IGDClient, UPNPError
from xml.parsers.expat import ExpatError
from socket import socket, AF_INET, SOCK_DGRAM, SOCK_STREAM, gaierror, error, \
SOL_SOCKET, SO_REUSEADDR, timeout
@@ -110,9 +110,10 @@ def enable_invite_btn(self, enable=True): pass
class UserFrmList(UserFrm):
def __init__(self, name, is_supporter, is_playing, pos, parent,
menu_args):
menu_args, yorg_client):
UserFrm.__init__(
self, name, is_supporter, pos, parent, menu_args, .72)
self.yorg_client = yorg_client
lab_args = menu_args.label_args
lab_args['scale'] = .046
lab_args['text_fg'] = self.menu_args.text_normal
@@ -139,7 +140,7 @@ def enable_invite_btn(self, enable=True): self.__enable_invite_btn = enable
def on_invite(self, usr_name):
self.eng.log('invite ' + usr_name)
self.invite_btn.disable()
self.notify('on_invite', self.eng.xmpp.find_usr(usr_name))
self.notify('on_invite', self.yorg_client.find_usr(usr_name))
def on_friend(self, usr_name):
self.eng.log('friend with ' + usr_name)
@@ -167,18 +168,16 @@ def on_unfriend(self, usr):
class UserFrmMatch(UserFrm):
def __init__(self, name, name_full, is_supporter, is_online, pos, parent,
menu_args):
def __init__(self, uid, usr, is_supporter, pos, parent, menu_args):
UserFrm.__init__(
self, name, name_full, is_supporter, is_online, pos, parent,
menu_args, 1.0)
self, uid, is_supporter, pos, parent, menu_args, 1.0)
self.frm['frameSize'] = (-.01, 1.06, .05, -.03)
lab_args = menu_args.label_args
lab_args['scale'] = .046
lab_args['text_fg'] = self.menu_args.text_normal
self.remove_btn = MPBtn(
self.frm, self, menu_args, 'assets/images/gui/remove.txo',
.92, self.on_remove, name_full.name, _("remove from the match"))
.92, self.on_remove, usr.uid, _("remove from the match"))
def on_remove(self, usr):
self.notify('on_remove', usr)
@@ -6,14 +6,14 @@
class InviteDialog(GameObject, Subject):
def __init__(self, menu_args, msg):
def __init__(self, menu_args, from_, roomname):
Subject.__init__(self)
GameObject.__init__(self)
self.user = msg['from'].bare
self.msg = msg
self.from_ = from_
self.roomname = roomname
self.dialog = YesNoDialog(
base.a2dBottomLeft,
text=_('%s has invited you to a match, do you agree?') % self.user,
text=_('%s has invited you to a match, do you agree?') % from_,
text_wordwrap=16,
text_fg=menu_args.text_active,
text_font=menu_args.font,
@@ -34,7 +34,7 @@ def __init__(self, menu_args, msg):
def on_btn(self, val):
self.eng.log('invite button ' + val)
self.notify('on_invite_answer', self.msg, val == 'yes')
self.notify('on_invite_answer', self.from_, self.roomname, val == 'yes')
def destroy(self):
self.eng.log('destroyed dialog ' + self.dialog['text'])
@@ -11,49 +11,50 @@
class MatchFrm(GameObject):
def __init__(self, menu_args):
def __init__(self, menu_args, yorg_client):
GameObject.__init__(self)
self.eng.log('created match form (init)')
self.yorg_client = yorg_client
self.room = ''
self.invited_users = [self.eng.xmpp.client.boundjid.bare]
self.invited_users = [yorg_client.myid]
self.menu_args = menu_args
lab_args = menu_args.label_args
lab_args['scale'] = .046
self.match_frm = DirectFrame(
frameSize=(-.02, 2.5, 0, .45),
frameColor=(.2, .2, .2, .5),
pos=(.04, 1, -.46), parent=base.a2dTopLeft)
usr = [usr for usr in self.eng.xmpp.users if usr.name == self.eng.xmpp.client.boundjid.bare][0]
usr = [usr for usr in yorg_client.users if usr.uid == yorg_client.myid][0]
frm = UserFrmMe(
self.eng.xmpp.client.boundjid.bare, self.eng.xmpp.client.boundjid.bare,
usr.is_supporter, True, (.1, 1, .38), self.match_frm, self.menu_args, .32)
yorg_client.myid, usr.is_supporter, (.1, 1, .38), self.match_frm,
self.menu_args, .32)
self.forms = [frm]
for i in range(0, 8):
row, col = i % 4, i / 4
DirectLabel(
text=str(i + 1) + '.', pos=(.06 + 1.24 * col, 1, .38 - .08 * row),
parent=self.match_frm, **lab_args)
def on_presence_available_room(self, msg):
room = str(JID(msg['muc']['room']).bare)
nick = str(msg['muc']['nick'])
self.eng.log('user %s has connected to the room %s' % (nick, room))
if nick == self.eng.xmpp.client.boundjid.bare: return
def on_presence_available_room(self, uid, room):
#room = str(JID(msg['muc']['room']).bare)
#nick = str(msg['muc']['nick'])
self.eng.log('user %s has connected to the room %s' % (uid, room))
if uid == self.yorg_client.myid: return
if room != self.room: return
found = False
for frm in self.forms:
lab = frm.lab.lab['text']
lab = lab.replace('\1smaller\1', '').replace('\2', '')
if lab.startswith('? '): lab = lab[2:]
if lab == nick:
if lab == uid:
found = True
frm.lab.lab['text'] = frm.lab.lab['text'][2:]
if not found:
idx = len(self.forms)
x = .1 + 1.24 * (idx / 4)
y = .38 - .08 * (idx % 4)
usr = [usr for usr in self.eng.xmpp.users if usr.name == nick][0]
frm = UserFrm(self.trunc(nick, 30), nick, usr.is_supporter,
usr = [usr for usr in self.yorg_client.users if usr.uid == uid][0]
frm = UserFrm(self.trunc(uid, 30), uid, usr.is_supporter,
usr.is_online,
(x, 1, y), self.match_frm, self.menu_args, 1.0)
self.forms += [frm]
@@ -84,14 +85,13 @@ def set_frm_pos(self, frm, i):
y = .38 - .08 * row
frm.frm.set_pos((x, 1, y))
def on_declined(self, msg):
usr = str(JID(msg['from']).bare)
self.eng.log('user %s has declined' % usr)
def on_declined(self, from_):
self.eng.log('user %s has declined' % from_)
for i, frm in enumerate(self.forms[:]):
lab = frm.lab.lab['text']
lab = lab.replace('\1smaller\1', '').replace('\2', '')
if lab.startswith('? '): lab = lab[2:]
if lab == usr:
if lab == from_:
for j in range(i + 1, 8):
if j < len(self.forms):
self.set_frm_pos(self.forms[j], j - 1)
@@ -104,15 +104,15 @@ def trunc(name, lgt):
return name
def on_invite(self, usr):
self.eng.log('match form: invited user ' + usr.name)
self.eng.log('match form: invited user ' + usr.uid)
idx = len(self.invited_users)
x = .1 + 1.24 * (idx / 4)
y = .38 - .08 * (idx % 4)
frm = UserFrmMatch('? ' + self.trunc(usr.name, 30), usr, usr.is_supporter, usr.is_online, (x, 1, y),
frm = UserFrmMatch('? ' + self.trunc(usr.uid, 30), usr, usr.is_supporter, (x, 1, y),
self.match_frm, self.menu_args)
frm.attach(self.on_remove)
self.forms += [frm]
self.invited_users += [usr.name]
self.invited_users += [usr.uid]
def on_start(self):
self.eng.log('match form: start')
@@ -138,8 +138,8 @@ def destroy(self):
class MatchFrmServer(MatchFrm):
def __init__(self, menu_args):
MatchFrm.__init__(self, menu_args)
def __init__(self, menu_args, yorg_client):
MatchFrm.__init__(self, menu_args, yorg_client)
btn_args = self.menu_args.btn_args
btn_args['scale'] = .06
Btn(text=_('Start'), pos=(1.2, 1, .03), command=self.on_start,
@@ -148,8 +148,8 @@ def __init__(self, menu_args):
class MatchFrmServerClient(MatchFrm):
def __init__(self, menu_args):
MatchFrm.__init__(self, menu_args)
def __init__(self, menu_args, yorg_client):
MatchFrm.__init__(self, menu_args, yorg_client)
lab_args = menu_args.label_args
lab_args['scale'] = .046
DirectLabel(
@@ -28,21 +28,23 @@ def title(self):
class MUC(Chat):
def __init__(self, dst):
def __init__(self, dst, yorg_client):
Chat.__init__(self, dst)
self.users = []
self.yorg_client = yorg_client
@property
def title(self):
is_me = lambda usr: usr == self.eng.xmpp.client.boundjid.bare
is_me = lambda usr: usr == self.yorg_client.myid
return ', '.join(sorted(self.users, key=is_me))
class MatchMsgFrm(GameObject):
def __init__(self, menu_args):
def __init__(self, menu_args, yorg_client):
GameObject.__init__(self)
self.eng.log('created match message form')
self.yorg_client = yorg_client
self.chat = None
self.msg_frm = DirectFrame(
frameSize=(-.02, 2.5, 0, 1.22),
@@ -146,18 +148,18 @@ def on_groupchat_msg(self, msg):
self.eng.log('received groupchat message from %s in the chat %s' %(msg['mucnick'], JID(msg['from']).bare))
str_msg = '\1italic\1' + src + '\2: ' + str(msg['body'])
if not self.chat:
self.chat = MUC(str(JID(msg['from']).bare))
self.chat = MUC(str(JID(msg['from']).bare), self.yorg_client)
self.chat.messages += [str_msg]
if self.dst_txt['text'] == '':
self.set_chat(self.chat)
elif self.chat.dst == str(JID(msg['from']).bare):
self.add_msg_txt(str_msg)
def on_presence_available_room(self, msg):
room = str(JID(msg['muc']['room']).bare)
nick = str(msg['muc']['nick'])
self.eng.log('user %s has logged in the chat %s' %(nick, room))
self.chat.users += [nick]
def on_presence_available_room(self, uid, room):
#room = str(JID(msg['muc']['room']).bare)
#nick = str(msg['muc']['nick'])
self.eng.log('user %s has logged in the chat %s' % (uid, room))
self.chat.users += [uid]
self.set_title(self.chat.title)
def on_presence_unavailable_room(self, msg):
@@ -170,7 +172,7 @@ def on_presence_unavailable_room(self, msg):
def add_groupchat(self, room, usr):
self.set_title(usr)
if not self.chat:
self.chat = MUC(room)
self.chat = MUC(room, self.yorg_client)
self.set_chat(self.chat)
def set_chat(self, chat):
@@ -420,15 +422,15 @@ def on_groupchat_msg(self, msg):
chat.closed = False
self.arrow_btn['frameTexture'] = 'assets/images/gui/message.txo'
def on_presence_available_room(self, msg):
if str(JID(msg['from']).bare) == self.curr_match_room:
self.match_msg_frm.on_presence_available_room(msg)
room = str(JID(msg['muc']['room']).bare)
nick = str(msg['muc']['nick'])
self.eng.log('user %s has logged in the chat %s' %(nick, room))
def on_presence_available_room(self, uid, room):
if room == self.curr_match_room:
self.match_msg_frm.on_presence_available_room(uid, room)
#room = str(JID(msg['muc']['room']).bare)
#nick = str(msg['muc']['nick'])
self.eng.log('user %s has logged in the chat %s' %(uid, room))
chat = self.__find_chat(room)
chat.users += [nick]
if str(JID(msg['from']).bare) != self.curr_match_room:
chat.users += [uid]
if room != self.curr_match_room:
if self.curr_chat.dst == room:
self.set_title(chat.title)
@@ -464,7 +466,7 @@ def add_groupchat(self, room, usr):
self.set_title(usr)
chat = self.__find_chat(room)
if not chat:
chat = MUC(room)
chat = MUC(room, self.yorg_client)
self.chats += [chat]
chat.users += [usr]
self.set_chat(chat)
@@ -489,6 +491,6 @@ def on_room_back(self):
def add_match_chat(self, room, usr):
if self.curr_match_room: return
self.curr_match_room = room
self.match_msg_frm = MatchMsgFrm(self.menu_args)
self.match_msg_frm = MatchMsgFrm(self.menu_args, self.yorg_client)
self.match_msg_frm.attach(self.on_match_msg_focus)
self.match_msg_frm.add_groupchat(room, usr)
Oops, something went wrong.

0 comments on commit 8c9dba4

Please sign in to comment.