File: start_server.py

package info (click to toggle)
openrpg 1.6.1-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 3,564 kB
  • ctags: 3,390
  • sloc: python: 25,165; xml: 11,229; makefile: 34; sh: 34
file content (182 lines) | stat: -rwxr-xr-x 5,899 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
#!/usr/bin/env python

import pyver
import sys
pyver.checkPyVersion()
import time
import gc
import getopt
import orpg.networking.mplay_server
import orpg.networking.meta_server_lib
import traceback


# Simple usuage text for request via help or command line errors
def usage( retValue ):
    print sys.argv[0] + " " + \
    "[-n Server Name]\n" + \
    "[-p]\n" + \
    "[-l Lobby Boot Password]\n" + \
    "[-r Run From???]\n" + \
    "[-h --help]\n\n" + \
    "Where -p is used to request meta registration.  If -p is given, the boot\n" + \
    "password and server name MUST be provided.  If no options are given, user\n" + \
    "will be prompted for information.\n\n"

    sys.exit( retValue )



if __name__ == '__main__':
    lobby_boot_pwd = ""
    name = ""
    post = "N"
    opt="N"

    gc.set_debug(gc.DEBUG_UNCOLLECTABLE)
    gc.enable()


    # See if we have command line arguments in need of processing
    try:
        (opts, args) = getopt.getopt( sys.argv[1:], "n:pl:h", "help" )

        for o in opts:
            # Server Name
            if o[0] in ( "-n", ):
                name = o[1]

            # Post server to meta
            if o[0] in ( "-p", ):
                post = 'Y'

            # Lobby Password
            if o[0] in ( "-l", ):
                lobby_boot_pwd = o[1]

            # Help
            if o[0] in ( "-h", "--help" ):
                usage( 0 )

    except:
        usage( 1 )


    # Now, validate that if we had options passed in, they make sense!  If
    # no options were passed in, follow the normal prompt for information
    # start up path.  If -p is passed in, make sure name and password is
    # also provided.
    if len(opts):
        if (post == 'Y') and ((len(name) == 0) or (len(lobby_boot_pwd) == 0)):
            usage( 1 )

    if (len(lobby_boot_pwd) == 0):
        lobby_boot_pwd = raw_input("Enter boot password for the Lobby:  ")

    # Only ask if we didn't pass in options and post isn't 'Y'
    if ( (post == 'N') and (opt == 'N') ):
        opt = raw_input("Do you want to post your server to the OpenRPG Meta Server list? (y,n)")
        if opt[0] == 'y' or opt[0] == 'Y':
            post = 'Y'
            
    # If we are going to post make sure we have a server name, if not, ask for it
    if ( post == 'Y' ) and (len(name) == 0 ):
        name = raw_input("Server Name?")

    # start server!
    orpg_server = orpg.networking.mplay_server.mplay_server()
    orpg_server.force_check = 1
    for index in range(len(sys.argv)-1):
        if (sys.argv[index] == "-v"):
            orpg_server.force_check=0


    if ( post == 'Y' ) and (len(name)):
        # Start the registration thread
        #  register servers
        orpg_server.register( name )

    orpg_server.print_help()
    orpg_server.groups['0'].boot_pwd = lobby_boot_pwd

    

    opt = "None"
    try:
        while (opt != "kill") and ( opt != "quit"):
            opt = raw_input("action?:")

            words = opt.split()

            if opt == "broadcast":
                msg = raw_input("Message:")
                orpg_server.broadcast(msg)
            elif opt == "dump":
                orpg_server.player_dump()
            elif opt == "dump groups":
                orpg_server.groups_list()
            elif opt == "get lobby boot password":
                print "Lobby boot password is:  " + orpg_server.groups['0'].boot_pwd
                print
            elif opt == "register":
                msg = raw_input("Enter server name:  ")
                orpg_server.register(msg)

            elif opt == "unregister":
                orpg_server.unregister()

            elif opt == "set lobby boot password":
                lobby_boot_pwd = raw_input("Enter boot password for the Lobby:  ")
                orpg_server.groups['0'].boot_pwd = lobby_boot_pwd

            elif len(words) == 2 and words[0] == "group":
                orpg_server.group_dump(words[1])
            elif opt == "help" or opt == "?" or opt == "h":
                orpg_server.print_help()
            elif opt == "search":
                msg = raw_input("Pattern:")
                orpg_server.search(msg)
            elif opt == "remove room":
                print "Removing a room will kick everyone in that room off your server."
                print "You might consider going to that room and letting them know what you are about to do."
                groupnumber = raw_input("Room group number:")
                orpg_server.remove_room(groupnumber)
            elif opt == "uptime": 
                orpg_server.uptime()
            elif opt == "roompasswords": 
                print orpg_server.RoomPasswords()
            elif opt == "list":
                orpg_server.player_list()
            elif opt == "log":
                orpg_server.console_log()
            elif opt == "log meta":
                orpg_server.toggleMetaLogging()
            elif len(words) > 0 and words[0] == "logfile":
                if len(words) > 1:
                    if words[1] == "off":
                        orpg_server.NetworkLogging(0)
                    elif words[1] == "on":
                        orpg_server.NetworkLogging(1)
                    elif words[1] == "split":
                        orpg_server.NetworkLogging(2)
                    else:
                        print "<command useage> logfile [off|on|split]" 
                else:
                    print orpg_server.NetworkLoggingStatus()
              
            elif opt == "kick":
                kick_id = raw_input("Kick Player #  ")
                kick_msg = raw_input("Reason(optional):  ")
                orpg_server.admin_kick(kick_id,kick_msg)
                

    except Exception, e:
        print "EXCEPTION: "+str(e)
        traceback.print_exc()
        raw_input("press <enter> key to terminate program")


    orpg_server.kill_server()