2006-05-11 08:00:37 +02:00
|
|
|
import pwd
|
|
|
|
import os
|
|
|
|
|
2006-05-11 20:46:34 +02:00
|
|
|
from Service import *
|
|
|
|
import presence
|
|
|
|
|
|
|
|
BUDDY_SERVICE_TYPE = "_olpc_buddy._tcp"
|
|
|
|
BUDDY_SERVICE_PORT = 666
|
|
|
|
|
|
|
|
GROUP_SERVICE_TYPE = "_olpc_buddy._udp"
|
|
|
|
GROUP_SERVICE_PORT = 6666
|
2006-05-11 08:00:37 +02:00
|
|
|
|
|
|
|
class Buddy:
|
|
|
|
def __init__(self, service, nick_name):
|
|
|
|
self._service = service
|
|
|
|
self._nick_name = nick_name
|
|
|
|
|
|
|
|
def get_service(self):
|
|
|
|
return self._service
|
2006-05-11 20:46:34 +02:00
|
|
|
|
|
|
|
def get_service_name(self):
|
|
|
|
return self._service.get_name()
|
2006-05-11 08:00:37 +02:00
|
|
|
|
|
|
|
def get_nick_name(self):
|
|
|
|
return self._nick_name
|
|
|
|
|
|
|
|
class Owner(Buddy):
|
|
|
|
def __init__(self):
|
|
|
|
ent = pwd.getpwuid(os.getuid())
|
|
|
|
nick = ent[0]
|
|
|
|
if not nick or not len(nick):
|
|
|
|
nick = "n00b"
|
|
|
|
|
2006-05-11 20:46:34 +02:00
|
|
|
service_name = nick + '.' + GROUP_SERVICE_TYPE
|
|
|
|
service = Service(service_name, '', '', GROUP_SERVICE_PORT)
|
2006-05-11 08:00:37 +02:00
|
|
|
|
2006-05-11 20:46:34 +02:00
|
|
|
Buddy.__init__(self, service, nick)
|
|
|
|
|
|
|
|
def register(self):
|
|
|
|
pannounce = presence.PresenceAnnounce()
|
|
|
|
pannounce.register_service(self._nick_name,
|
|
|
|
BUDDY_SERVICE_PORT,
|
|
|
|
BUDDY_SERVICE_TYPE,
|
|
|
|
nickname = self._nick_name)
|