Skip to content
This repository has been archived by the owner on Nov 9, 2021. It is now read-only.

Commit

Permalink
add irc bridge plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
mekolat committed May 22, 2016
1 parent 6cd23c5 commit b219bdc
Show file tree
Hide file tree
Showing 6 changed files with 448 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.pyc
7 changes: 5 additions & 2 deletions headless.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import plugins
from utils import extends
from itemdb import load_itemdb
from logicmanager import logic_manager


@extends('smsg_player_warp')
Expand All @@ -31,7 +32,7 @@ def map_login_success(data):

if __name__ == '__main__':
logging.basicConfig(format="[%(asctime)s] %(message)s",
level=logging.INFO,
level=logging.WARNING,
datefmt="%Y-%m-%d %H:%M:%S")
config = ConfigParser()
config.read('manachat.ini')
Expand All @@ -47,6 +48,8 @@ def map_login_success(data):
charname=config.get('Player', 'charname'))

try:
asyncore.loop()
while True:
asyncore.loop(timeout=0.2, count=5)
logic_manager.tick()
except KeyboardInterrupt:
mapserv.cleanup()
1 change: 1 addition & 0 deletions irc_bridge_db.pkl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(d.
17 changes: 15 additions & 2 deletions net/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@ class SocketWrapper(asyncore.dispatcher_with_send):
"""
socket wrapper with file-like read() and write() methods
"""
def __init__(self, host=None, port=0, buffer_size=1500, protodef={}):
def __init__(self, host=None, port=0, buffer_size=1500, protodef={}, onclose=None):
asyncore.dispatcher_with_send.__init__(self)
self.buffer_size = buffer_size
self.read_buffer = ''
self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
self.protodef = protodef
self.raw = False
self.raw = True
self.onclose = onclose
if protodef == {}:
netlog.warning("protodef is empty")
if host is not None:
Expand Down Expand Up @@ -69,6 +70,18 @@ def write(self, data):
else:
self.send(data)

def handle_error(self):
self.handle_close()
return

def handle_expt(self):
return

def handle_close(self):
self.close()
if self.onclose is not None:
self.onclose()


def send_packet(srv, opcode_, *fields):
class C:
Expand Down
5 changes: 4 additions & 1 deletion net/mapserv.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
def smsg_ignore(data):
pass

@extendable
def on_close():
netlog.warning("connection to map server lost")

@extendable
def smsg_being_chat(data):
Expand Down Expand Up @@ -1169,7 +1172,7 @@ def cmsg_storage_close():
def connect(host, port):
global server, beings_cache
beings_cache = BeingsCache(cmsg_name_request)
server = SocketWrapper(host=host, port=port, protodef=protodef)
server = SocketWrapper(host=host, port=port, protodef=protodef, onclose=on_close)
timers.append(Schedule(15, 20, cmsg_map_server_ping))


Expand Down
Loading

0 comments on commit b219bdc

Please sign in to comment.