################################################################################
## Copyover
################################################################################
copyover_file = "../lib/misc/copyover"
def copyover():
''' Saves the telopt auxiliary data of all active connections with set players
to be restored after the copyover is complete.'''
set = storage.StorageSet()
list = storage.StorageList()
# Iterate through the sockets and save the ones with connected users. Ignore
# the others since they're simply disconnected.
for sk in mudsock.socket_list():
if sk.ch:
s = storage.StorageSet()
s.storeString("k", sk.ch.name)
s.storeSet("v", sk.telopt.store())
list.add(s)
# Store and close the set
set.storeList("list", list)
set.write(copyover_file)
set.close()
def copyover_complete(info):
''' Loads socket auxiliary data for the active connections from a file. '''
set = storage.StorageSet(copyover_file)
# Read the data into a dict.
data = { }
for s in set.readList("list").sets():
data[s.readString("k")] = s.readSet("v")
# Iterate through sockets, and if a player is connected, restore the aux data
# To their socket.
for sk in mudsock.socket_list():
if sk.ch is not None and data.has_key(sk.ch.name):
sk.telopt.load(data[sk.ch.name])
# Close the set
set.close()
# Register a hook so copyover_complete runs.
hooks.add("copyover_complete", copyover_complete)
def cmd_copyover(ch, cmd, arg):
'''Restarts the mud, and keep all sockets connected. But first
call the copyover function from advanced_telopt to keep track
of all our special data there.'''
from telopt import copyover
copyover()
mudsys.do_copyover()
I'll fix the TTYPE negotiation resetting for TT++.
From what I understand the typical MUD creates a socket for a given port, and on a copyover execl() is called, which destroys the old process, but somehow it doesn't destroy the socket - even though one would expect it would. As such the socket id and a list of connections can be saved, restored after the copyover, and things continue as if nothing happened.