package main

import (
	"WorldTester/pb"
	"common/logger"
	"log"
	"net"
)

func init() {
	RegisterMessage(pb.MSGID_MsgID_Logon_Response, &pb.ResponseLogon{}, LoginResponseHandler)


}


func LoginResponseHandler(conn net.Conn, header pb.MessageHeader, msg interface{}) {
	resp := msg.(*pb.ResponseLogon)
	v := m_map_players.Get(header.PlayerID)
	if v == nil {
		logger.Info("recvd login message response:%+v header:%+v not found playerid", *resp, header)
		return
	}
	if resp.Error != 1 {
		logger.Info("uid %d login failed with error:%+v", header.PlayerID, resp.Error)
		return
	}
	player := v.(*PlayerInfo)
	player.state = STATE_PLAYER_LOGINED

	log.Println("receive LoginResponseHandler resp=%+v:", resp)
	if player.isHost {
		SendCreateClub(player)
	} else {
		SendJoinClub(player)
		log.Println("SendJoinClub")
	}
}

