Files
AVA2/runtime/login_view.py
T

106 lines
3.7 KiB
Python

# -*- coding: utf-8 -*-
# Developer view for the AVA2 port. Uses the original net extension names/callbacks.
# Original UI uses its separate script bootstrap; this controller is for transport verification.
import net
class LoginView(object):
def __init__(self):
self.phase = 'login'
self.message = 'Configure an isolated auth and game endpoint, then connect.'
self.selected = -1
self.login_starts = 0
self.handshakes = 0
self.refreshes = 0
self.inventory_refreshes = 0
self.status_refreshes = 0
net.SetHandler(self)
net.SetAccountConnectorHandler(self)
net.SetPhaseWindow(net.PHASE_WINDOW_LOGIN, self)
net.SetPhaseWindow(net.PHASE_WINDOW_SELECT, self)
net.SetPhaseWindow(net.PHASE_WINDOW_GAME, self)
def Connect(self, game_host, game_port, auth_host, auth_port, account, password):
net.SetLoginInfo(account, password)
net.SetPacketSequenceMode()
net.ConnectToAccountServer(game_host, game_port, auth_host, auth_port)
self.phase = 'connecting'
self.message = 'Connecting...'
self.selected = -1
def Cancel(self):
net.Disconnect()
self.phase = 'login'
self.message = 'Connection cancelled. You can retry.'
self.selected = -1
def OnHandShake(self):
self.handshakes += 1
def SetLoginPhase(self):
self.phase = 'login'
self.selected = -1
self.message = 'Game connection closed. You can reconnect.'
def OnLoginStart(self):
self.login_starts += 1
self.message = 'Authentication accepted. Reading character slots...'
def OnConnectFailure(self):
self.phase = 'login'
self.message = 'Cannot connect. Check the endpoint and retry.'
def OnLoginFailure(self, reason):
self.phase = 'login'
self.message = 'Login failed: ' + reason
self.selected = -1
def SetSelectCharacterPhase(self):
self.phase = 'select'
self.message = 'Choose an occupied character slot.'
def SetSelectEmpirePhase(self):
self.phase = 'empire'
self.message = 'Empire creation is pending in this development view.'
def Refresh(self):
self.refreshes += 1
def SetLoadingPhase(self):
self.phase = 'loading'
self.message = 'Server accepted selection. Loading game...'
def SetGamePhase(self):
self.phase = 'game'
self.message = 'In game phase.'
def RefreshInventory(self):
self.inventory_refreshes += 1
def RefreshStatus(self):
self.status_refreshes += 1
def Choose(self, slot):
if self.phase != 'select':
raise ValueError('Character list is not ready')
if not net.GetAccountCharacterSlotDataInteger(slot, net.ACCOUNT_CHARACTER_SLOT_ID):
raise ValueError('This character slot is empty')
self.selected = slot
def Enter(self):
if self.selected < 0:
raise ValueError('Choose an occupied character slot first')
net.SendSelectCharacterPacket(self.selected)
self.phase = 'entering'
self.message = 'Selection sent. Waiting for server loading phase...'
def Snapshot(self):
slots = []
for slot in xrange(5):
slots.append((net.GetAccountCharacterSlotDataInteger(slot, net.ACCOUNT_CHARACTER_SLOT_ID),
net.GetAccountCharacterSlotDataString(slot, net.ACCOUNT_CHARACTER_SLOT_NAME),
net.GetAccountCharacterSlotDataInteger(slot, net.ACCOUNT_CHARACTER_SLOT_LEVEL),
net.GetAccountCharacterSlotDataInteger(slot, net.ACCOUNT_CHARACTER_SLOT_RACE)))
return self.phase, self.message, self.selected, slots
view = LoginView()