1 |
#!/usr/bin/env python |
#!/usr/bin/env python |
2 |
# |
# |
3 |
#Minë. Mundo Interactivo-Narrativo en Español [Tierra-Media] |
#Minë. Mundo Interactivo-Narrativo en Español [Tierra-Media] |
4 |
#Copyright (C) 2002 Pablo Ruiz Múzquiz |
#Copyright (C) 2002 Pablo Ruiz Múzquiz |
5 |
# |
# |
6 |
# |
# |
7 |
#This program is free software; you can redistribute it and/or modify |
#This program is free software; you can redistribute it and/or modify |
8 |
#it under the terms of the GNU General Public License as published by |
#it under the terms of the GNU General Public License as published by |
9 |
#the Free Software Foundation; either version 2 of the License, or |
#the Free Software Foundation; either version 2 of the License, or |
10 |
#(at your option) any later version. |
#(at your option) any later version. |
11 |
# |
# |
12 |
#This program is distributed in the hope that it will be useful, |
#This program is distributed in the hope that it will be useful, |
13 |
#but WITHOUT ANY WARRANTY; without even the implied warranty of |
#but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 |
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 |
#GNU General Public License for more details. |
#GNU General Public License for more details. |
16 |
# |
# |
17 |
#You should have received a copy of the GNU General Public License |
#You should have received a copy of the GNU General Public License |
18 |
#along with this program; if not, write to the Free Software |
#along with this program; if not, write to the Free Software |
19 |
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
20 |
# |
# |
21 |
# |
# |
22 |
#Fichero: mine.py |
#Fichero: mine.py |
23 |
|
|
24 |
"""Código inicial de arranque del servidor.""" |
"""Código inicial de arranque del servidor.""" |
25 |
|
|
26 |
import sys |
import sys |
27 |
from connection import * |
from connection import * |
28 |
from cronomine import * |
from cronomine import * |
29 |
from mundo import * |
from mundo import * |
30 |
from interfazpj import * |
from interfazpj import * |
31 |
from sala import * |
from sala import * |
32 |
from personajejugador import * |
from personajejugador import * |
33 |
from logo import * |
from logo import * |
34 |
from utils import * |
from utils import * |
35 |
|
|
36 |
DIRECCION_IP = "" |
DIRECCION_IP = "" |
37 |
PUERTO = 2000 |
PUERTO = 2000 |
38 |
|
|
39 |
def nuevo_cliente(handler): |
def nuevo_cliente(handler): |
40 |
"""Responde a una peticion de un cliente. |
"""Responde a una peticion de un cliente. |
41 |
|
|
42 |
Se acepta la conexión y crea un nuevo InterfazPJ asociado |
Se acepta la conexión y crea un nuevo InterfazPJ asociado |
43 |
a la conexión nueva. |
a la conexión nueva. |
44 |
""" |
""" |
45 |
conn = handler.accept(None, None) |
conn = handler.accept(None, None) |
46 |
interfaz = InterfazPJ(conn) |
interfaz = InterfazPJ(conn) |
47 |
escribir("Conectado nuevo cliente desde " + conn.ip + ".") |
escribir("Conectado nuevo cliente desde " + conn.ip + ".") |
48 |
|
|
49 |
|
|
50 |
def preparar_salida(): |
def preparar_salida(): |
51 |
"""Ejecuta todas las acciones de limpieza necesarias al salir.""" |
"""Ejecuta todas las acciones de limpieza necesarias al salir.""" |
52 |
escribir("Saliendo del programa...") |
escribir("Saliendo del programa...") |
53 |
|
|
54 |
# # Enviar al limbo a todos los jugadores que esten conectados |
# # Enviar al limbo a todos los jugadores que esten conectados |
55 |
# for personaje in Mundo.pjs_activos.values(): |
# for personaje in Mundo.pjs_activos.values(): |
56 |
# escribir("Enviando al limbo a " + personaje.id) |
# escribir("Enviando al limbo a " + personaje.id) |
57 |
# Mundo_enviar_al_limbo(personaje) |
# Mundo_enviar_al_limbo(personaje) |
58 |
|
|
59 |
Mundo.conn_handler.close_all() |
Mundo.conn_handler.close_all() |
60 |
Mundo_salvar_todo() |
Mundo_salvar_todo() |
61 |
escribir("\n\n********CRASH******\n\n") |
escribir("\n\n********CRASH******\n\n") |
62 |
cerrar_log() |
cerrar_log() |
63 |
|
|
64 |
# Entrada y bucle principal de la aplicacion |
# Entrada y bucle principal de la aplicacion |
65 |
|
|
66 |
print color(33) + logo() + finl |
print color(33) + logo() + finl |
67 |
print |
print |
68 |
|
|
69 |
Mundo.conn_handler = ConnectionHandler(DIRECCION_IP, PUERTO, nuevo_cliente) |
Mundo.conn_handler = ConnectionHandler(DIRECCION_IP, PUERTO, nuevo_cliente) |
70 |
print "Servidor activado y a la escucha en puerto " + str(PUERTO) + "." |
print "Servidor activado y a la escucha en puerto " + str(PUERTO) + "." |
71 |
|
|
72 |
Mundo.cronoMine_control = CronoMineControl() |
Mundo.cronoMine_control = CronoMineControl() |
73 |
|
|
74 |
# Al salir del programa hay que salvar todas las salas y personajes |
# Al salir del programa hay que salvar todas las salas y personajes |
75 |
sys.exitfunc = preparar_salida |
sys.exitfunc = preparar_salida |
76 |
|
|
77 |
|
|
78 |
Mundo_inicializar() |
Mundo_inicializar() |
79 |
|
|
80 |
try: |
try: |
81 |
|
|
82 |
while 1: |
while 1: |
83 |
Mundo.conn_handler.run() |
Mundo.conn_handler.run() |
84 |
Mundo.cronoMine_control.run() |
Mundo.cronoMine_control.run() |
85 |
|
|
86 |
except KeyboardInterrupt: |
except KeyboardInterrupt: |
87 |
escribir("Interrumpido manualmente por el operador") |
escribir("Interrumpido manualmente por el operador") |
88 |
|
|