# along with this program; if not, write to the # Free Software Foundation, Inc., # 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA # ################################################### import logging import uuid import gettext from horizons.network.common import * from horizons import network from horizons.network import packets, find_enet_module from horizons.network import NetworkException, SoftNetworkException from horizons.i18n.utils import find_available_languages enet = find_enet_module(client = False) MAX_PEERS = 4095 CONNECTION_TIMEOUT = 500 PROTOCOLS = [0, 1] logging.basicConfig(format = '[%(asctime)-15s] [%(levelname)s] %(message)s', level = logging.DEBUG) class Server(object): def __init__(self, hostname, port, statistic_file=None): packets.SafeUnpickler.set_mode(client = False) self.host = None self.hostname = hostname self.port = port self.statistic = {
# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the # Free Software Foundation, Inc., # 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA # ################################################### import logging import datetime from horizons.network import packets from horizons import network from horizons.network.common import * from horizons.network import find_enet_module enet = find_enet_module() # during pyenets move to cpython they renamed a few constants... if not hasattr(enet, 'PEER_STATE_DISCONNECTED') and hasattr(enet, 'PEER_STATE_DISCONNECT'): enet.PEER_STATE_DISCONNECTED = enet.PEER_STATE_DISCONNECT # maximal peers enet should handle MAX_PEERS = 1 # time in ms the client will wait for a packet # on error client may wait twice that time SERVER_TIMEOUT = 5000 # current server/client protocol the client understands # increment that after incompatible protocol changes SERVER_PROTOCOL = 0 class ClientMode(object): Server = 0
# # This program 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 General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the # Free Software Foundation, Inc., # 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA # ################################################### import cPickle from horizons.network import find_enet_module enet = find_enet_module() __version__ = '0.1' __all__ = ['packet', 'packetlist'] PICKLE_PROTOCOL = 2 packetlist = [] class packet: def serialize(self): return cPickle.dumps(self, PICKLE_PROTOCOL) def send(self, peer, channelid=0): packet = enet.Packet(self.serialize(), enet.PACKET_FLAG_RELIABLE)