mirror of
https://github.com/Wesley-DeMontigny/WLUS.git
synced 2026-02-09 03:28:37 -06:00
67 lines
2.8 KiB
Python
67 lines
2.8 KiB
Python
import pyraknet.server as Server
|
|
from pyraknet.messages import Address
|
|
from pyraknet.bitstream import *
|
|
from GameManager import Session, SessionState
|
|
from ServerUtilities import *
|
|
import uuid
|
|
from passlib.hash import sha256_crypt
|
|
|
|
def HandleHandshake(Server : GameServer, data : bytes, address : Address):
|
|
stream = ReadStream(data)
|
|
clientVersion = stream.read(c_ulong)
|
|
|
|
Server.send(getHandshake(clientVersion, 1), address)
|
|
|
|
def HandleLogin(Server : GameServer, data : bytes, address : Address):
|
|
stream = ReadStream(data)
|
|
|
|
#There's a lot of other stuff in this packet but I think this is all we really need
|
|
username = stream.read(str, allocated_length=33)
|
|
password = stream.read(str, allocated_length=41)
|
|
|
|
packet, response, userKey, ID = LoginResponse(Server, username, password)
|
|
Server.send(packet, address)
|
|
if(response == LoginResponseEnum.Success):
|
|
session = Session()
|
|
session.address = address
|
|
session.userKey = userKey
|
|
session.accountID = ID
|
|
session.State = SessionState.LoggingIn
|
|
session.accountUsername = username
|
|
Server.GameManager.activeSessions.append(session)
|
|
|
|
def LoginResponse(Server : Server, Username : str, Password: str):
|
|
packet = WriteStream()
|
|
DB = Server.GameManager.ServerDB
|
|
userInfo = DB.Tables["Accounts"].select(["Banned", "Password", "ID"], "Username = '{}'".format(Username))[0]
|
|
print("Attempted login with username '{}' and password '{}'".format(Username, Password))
|
|
response = None
|
|
if (userInfo["Banned"] != 1 and sha256_crypt.verify(Password, userInfo["Password"])):#Success
|
|
response = LoginResponseEnum.Success
|
|
print("Login accepted!")
|
|
else:#Just put wrong info for now
|
|
response = LoginResponseEnum.InvalidLoginInfo
|
|
writeHeader(packet, PacketHeader.LoginResponse)
|
|
packet.write(c_uint8(response))
|
|
packet.write(CString("Talk_Like_A_Pirate", allocated_length=33))
|
|
packet.write(CString("", allocated_length=33*7))
|
|
packet.write(c_ushort(1))
|
|
packet.write(c_ushort(10))#Version Major, Current and Minor
|
|
packet.write(c_ushort(64))
|
|
userKey = (str(uuid.uuid4()))
|
|
packet.write(userKey[0:18], allocated_length=33)
|
|
packet.write(CString("127.0.0.1", allocated_length=33))#World Instance IP
|
|
packet.write(CString("127.0.0.1", allocated_length=33))#Chat Instance IP
|
|
packet.write(c_uint16(2002))#World Port
|
|
packet.write(c_ushort(3003))#Chat Port
|
|
packet.write(CString('0', allocated_length=33))#Some other IP
|
|
packet.write(CString('00000000-0000-0000-0000-000000000000', allocated_length=37))
|
|
packet.write(c_ulong(0))
|
|
packet.write(CString('US', allocated_length=3))#US Localization
|
|
packet.write(c_bool(False))
|
|
packet.write(c_bool(False))
|
|
packet.write(c_ulonglong(0))
|
|
packet.write("Hello there ;D", length_type=c_uint16)#Custom error message
|
|
packet.write(c_uint16(0))
|
|
packet.write(c_ulong(4))
|
|
return packet, response, userKey[0:18], userInfo["ID"] |