Vega strike Python Modules doc  0.5.1
Documentation of the " Modules " folder of Vega strike
 All Data Structures Namespaces Files Functions Variables
server_lib.py
Go to the documentation of this file.
1 import VS
2 import Director
3 import server
4 import launch
5 import dynamic_mission
6 import mission_lib
7 import guilds
8 import vsrandom
9 import universe
10 import faction_ships
11 import custom
12 import campaign_lib
13 
15  return server.getDirector()
16 
17 def player_docked(self):
18  nam = self.docked_un.getName()
19  VS.IOmessage(0,'game','news',self.callsign+' has docked to the '+nam)
20  VS.IOmessage(0,'game','all',self.callsign+' has docked to the '+nam)
21  #if self.objectives>0:
22  # VS.eraseObjective(self.objectives-1)
23 
26 
27 def player_undocked(self):
28  if not self.docked_un:
29  print 'Base for'+self.callsign+'blew up!'
30  return
31 
33  nam = self.docked_un.getName()
34 
36  VS.IOmessage(0,'game','news',self.callsign+' has undocked from the '+nam)
37  VS.IOmessage(0,'game','all',self.callsign+' has undocked from the '+nam)
38  #self.objectives=1+VS.addObjective('Dock to the '+nam+' again')
39  #VS.setCompleteness(self.objectives-1, -0.3)
40 
41 def player_joined(self):
42  self.sendMessage('Welcome, '+self.callsign+' to the server.')
43  campaign_lib.resetCampaigns(self.player_num)
44 
45 def player_execute(self):
46  self.player_num=self.current_un.isPlayerStarship()
47 
48 def server_init(self):
49  from trading import trading
50  from random_encounters import random_encounters
51  import dynamic_universe
52  self.loops = [
53  # Cannot handle so many units yet??? Bandwidth usage low but sends tons of FIREREQUEST packets clogging up the whole thing
54  # Also, respawning seems broken for this. (????)
55  #random_encounters (8000,40000,500,3,2,.6,.25,.1,2000),
56  #trading (),
57  #dynamic_universe
58  ]
59 
60 def server_execute(self):
61  if (self.loopnum % 10000) == 0:
62  pass
63  #VS.IOmessage(0,"game","all","Howdy! This server has run for "+str(self.loopnum)+" Python loops and has peaked at "+str(VS.getNumPlayers())+" players online!")
64 
65 def fixCallsign(callsign):
66  return callsign.lower().replace(' ','_')
67 
68 def placeBounty(callsign, amt):
69  srv = serverDirector()
70  donor = srv.getPlayer(VS.getCurrentPlayer())
71  plrcreds = player.current_un.getCredits()
72  if plrcreds<amt:
73  if plrcreds+1.0<amt:
74  return False
75  else:
76  amt=plrcreds
77  player.current_un.setCredits(plrcreds-amt)
78  callsign = fixCallsign(callsign)
79 
80  if Director.getSaveDataLength(0,"bounty_"+callsign) < 1:
81  Director.pushSaveData(0,"bounty_"+callsign, amt)
82  else:
83  oldamt = Director.getSaveData(0,"bounty_"+callsign,0)
84  Director.putSaveData(0,"bounty_"+callsign,0,amt+oldamt)
85 
86 
87 commandinfo = {
88  "help": (0, "/help [command]", "Gives a list of commands or describes one."),
89  "write": (1, "/write callsign text...", "Gives a personal message to callsign."),
90  "userlist": (0, "/userlist", "Lists users in this starsystem"),
91 }
92 authcommandinfo = {
93  "shiplist": (1, "/shiplist pagenum", "Lists all the ships available"),
94  "launchme": (1, "/launchme ship [faction] [quantity]", "Launches a ship around yourself"),
95  "launchtarg": (1, "/launchtarg ship [faction] [quantity]", "Launches a ship around your computer target"),
96  "launch": (2, "/launch ship aroundship [faction] [quantity]", "Launches a ship around 'aroundship'"),
97  "reload": (0, "/reload", "Reloads the server_lib.py file"),
98  "setadmin": (2, "/setadmin callsign level", "Sets player either to have 1"),
99  }
100 
101 aliasinfo = {
102  "message": "write", "whisper": "write",
103  "shout": "say",
104  "info": "help", "?": "help",
105  "reload2": "reload",
106  }
107 
108 def getCommandInfo(command, auth=True):
109  if command in aliasinfo:
110  command = aliasinfo[command]
111  cmdinfo=None
112  if auth>=1 and command in authcommandinfo:
113  cmdinfo = authcommandinfo[command]
114  elif command in commandinfo:
115  cmdinfo = commandinfo[command]
116  return cmdinfo
117 
118 def processMessage(player, auth, command, args, id=''):
119  if command in aliasinfo:
120  command = aliasinfo[command]
121  #cmdinfo = getCommandInfo(command, auth)
122  if auth<1 and command in authcommandinfo:
123  player.sendMessage("#884400You must be authorized to use "+command)
124  return
125  #if cmdinfo and len(args)<cmdinfo[0]:
126  # processMessage(player,True,"help",[command])
127  # return
128  if command=='help':
129  if len(args)<1:
130  cmdstr = '#8800cc'+' '.join(commandinfo)
131  if auth>=1:
132  cmdstr += '#cc0088 '+' '.join(authcommandinfo)
133  player.sendMessage('#888800Valid commands: '+cmdstr)
134  else:
135  cmdinfo = getCommandInfo(args[0], True)
136  if cmdinfo and len(cmdinfo)>=3:
137  player.sendMessage("#888800Usage: #880088"+cmdinfo[1]+"#888800 - "+cmdinfo[2])
138  else:
139  player.sendMessage("#884400/"+args[0]+" does not exist. Use /help for a list of commands.")
140  elif command=='reload':
141  if auth<1:
142  return
143  vsmod=VS
144  reload(__import__('server_lib'))
145  vsmod.IOmessage(0,"game","all","The server python script has been reloaded.")
146  elif command=='userlist':
147  cstr = '#44cc44Users on the server:#888800'
148  print len(serverDirector().playerlist)
149  for x in serverDirector().playerlist:
150  #print x
151  #print x.callsign
152  if x.callsign:
153  cstr += ' '+x.callsign
154  player.sendMessage(cstr)
155  elif command=='shipinfo':
156  response = []
157  if len(args)>=1:
158  callsign = fixCallsign(args[0])
159  if Director.getSaveDataLength(0,"bounty_"+callsign):
160  amt = Director.getSaveData(0,"bounty_"+callsign,0)
161  if amt > 1000.:
162  response.append("WANTED for %g credits!"%amt)
163  if callsign=='ai':
164  response.append("* Artifically Intelligent *")
165  if id:
166  custom.respond(response,None,id)
167  else:
168  for msg in response:
169  player.sendMessage(msg)
170  elif command=='shiplist':
171  cnt=0
172  min=-1
173  max=-1
174  cstr=''
175  if 1: #try:
176  page=int(args[0])
177  cstr = '#44cc44Available ships (#888800'+str(page)+'#44cc44):#888800'
178  num=10
179  min=(page-1)*num
180  max=page*num
181  else: #except:
182  min=-1
183  if min<0:
184  processMessage(player,False,"help",[command])
185  else:
186  shiplist=faction_ships.stattableexp.keys()
187  shiplist.sort()
188  for x in shiplist:
189  cnt+=1
190  if cnt>=min and cnt<max:
191  cstr+= ' '+x
192  player.sendMessage(cstr)
193  elif command=='launcheach':
194  if auth<1:
195  return
196  shiplist = faction_ships.stattableexp.keys()
197  for x in shiplist:
198  processMessage(player,1,"launchme",[x])
199  elif command=='setadmin':
200  if len(args)<2:
201  return
202  if auth<1:
203  return
204  playerto = serverDirector().getPlayerByCallsign(args[0])
205  if not playerto:
206  print args[0]
207  player.sendMessage("#884400Cannot find player "+args[0])
208  return
209  print args
210  value=0.0
211  if args[1]=='yes' or args[1]=='1':
212  value=1.0
213  pnum=playerto.player_num
214  if Director.getSaveDataLength(pnum, 'serveradmin')<1:
215  Director.pushSaveData(pnum, 'serveradmin', value)
216  else:
217  Director.putSaveData(pnum, 'serveradmin', 0, value)
218  playerto.sendMessage("Your admin status set to "+str(value))
219  elif command=='write':
220  if len(args)<1:
221  return
222  playerto = serverDirector().getPlayerByCallsign(args[0])
223  if not playerto:
224  player.sendMessage("#884400Cannot find player "+args[0])
225  return
226  playerto.sendMessage(' '.join(args[1:]), player.callsign)
227  player.sendMessage('Message to '+args[0]+': '+(' '.join(args[1:])))
228  elif command=='say':
229  VS.IOmessage(0, player.callsign,'all',' '.join(args))
230  elif command=='launchme' or command=='launchtarg' or command=='launch':
231  if auth<1:
232  return
233  if len(args)<1:
234  return
235  factquan=()
236  if command=="launchtarg" or command=="launchme":
237  if not player.current_un:
238  player.sendMessage("#884400Use /launch <unit> <aroundname> to launch when you are null.")
239  return
240  if len(args)>=3:
241  factquan=(args[1],args[2])
242  elif len(args)>=2:
243  factquan=(args[1],)
244  targun = player.current_un
245  if command=="launchtarg":
246  metarg=targun.GetTarget()
247  if metarg:
248  targun = metarg
249  else:
250  if len(args)<2:
251  processMessage(player,False,"help",[command])
252  return
253  if len(args)>=4:
254  factquan=(args[2],args[3])
255  elif len(args)>=3:
256  factquan=(args[2],)
257  targunname = args[1].lower()
258  iter = VS.getUnitList()
259  while iter.notDone():
260  targun=iter.current()
261  if targun.getName().lower()==targunname:
262  break
263  if targun.getFullname().lower()==targunname:
264  break
265  iter.advance()
266  faction = targun.getFactionName()
267  type=args[0]
268  quantity=1
269  for a in factquan:
270  try:
271  int(a)
272  quantity=int(a)
273  print quantity
274  except ValueError:
275  faction=a
276  print faction
277  fgname='AI'
278  ainame='default'
279  launch.launch_wave_around_unit(fgname,faction,type,ainame,quantity,2000.0,4000.0,targun)
280  else:
281  processMessage(player, auth, "help", [command])
282