<commit_before>package game

import (
	"bufio"
	"net"
	"strconv"
	"util"
	"user"
)

type PlayerManager struct {
	parent        *Container
	onlinePlayers util.BeanSlice
	userManager *user.UserManager
}

func NewPlayerManager(parent *Container) *PlayerManager {
	this := new(PlayerManager)
	this.onlinePlayers = util.BeanSlice{}
	this.parent = parent
	this.userManager = user.NewUserManager()
	return this
}

func (this *PlayerManager) Login(conn net.Conn) (player *Player, err error) {
	proto := this.parent.parent.proto
	if cmd, err := proto.ReadCommand(bufio.NewReader(conn)); err == nil {
		if cmd.CommandID == CMDLOGIN && len(cmd.Arguments) == 2 {
			userid := cmd.Arguments[0]
			id, _ := strconv.ParseUint(cmd.Arguments[0], 10, 64)
			passwd := cmd.Arguments[1]

			resp := proto.CreateResponse()
			
			user := this.userManager.AddUser(userid, passwd)
			if user == nil {
				user = this.userManager.GetUser(userid, passwd)
			}else{
				this.userManager.Save()
			}
			
			if user == nil{
				resp.ErrNo = ErrFormat
				resp.Data = []string{"0"}
			}else{
				resp.ErrNo = ErrOK
				resp.Data = []string{"1"}
				if _, err := conn.Write(resp.Serialize()); err == nil {
					player = NewPlayer(id, passwd, "dislay name", conn, this)
					this.onlinePlayers = append(this.onlinePlayers, player)
					return player, nil
				}
			}
		}<commit_msg>write response when user log in fail<commit_after>package game

import (
	"bufio"
	"net"
	"strconv"
	"util"
	"user"
)

type PlayerManager struct {
	parent        *Container
	onlinePlayers util.BeanSlice
	userManager *user.UserManager
}

func NewPlayerManager(parent *Container) *PlayerManager {
	this := new(PlayerManager)
	this.onlinePlayers = util.BeanSlice{}
	this.parent = parent
	this.userManager = user.NewUserManager()
	return this
}

func (this *PlayerManager) Login(conn net.Conn) (player *Player, err error) {
	proto := this.parent.parent.proto
	if cmd, err := proto.ReadCommand(bufio.NewReader(conn)); err == nil {
		if cmd.CommandID == CMDLOGIN && len(cmd.Arguments) == 2 {
			userid := cmd.Arguments[0]
			id, _ := strconv.ParseUint(cmd.Arguments[0], 10, 64)
			passwd := cmd.Arguments[1]

			resp := proto.CreateResponse()
			
			user := this.userManager.AddUser(userid, passwd)
			if user == nil {
				user = this.userManager.GetUser(userid, passwd)
			}else{
				this.userManager.Save()
			}
			
			if user == nil{
				resp.ErrNo = ErrFormat
				resp.Data = []string{"0"}
				conn.Write(resp.Serialize())
			}else{
				resp.ErrNo = ErrOK
				resp.Data = []string{"1"}
				if _, err := conn.Write(resp.Serialize()); err == nil {
					player = NewPlayer(id, passwd, "dislay name", conn, this)
					this.onlinePlayers = append(this.onlinePlayers, player)
					return player, nil
				}
			}
		}
{'fraction_non_alphanumeric': 0.13933236574746008, 'fraction_numerical': 0.00725689404934688, 'mean_word_length': 3.5049019607843137, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1035846', 'n_tokens_mistral': 1084, 'n_tokens_neox': 930, 'n_words': 215}