<commit_before>package server

type IncomingMessage struct {
	Client Client
	Player *Player
	Body   map[string]string
}

func newIncomingMessage(client Client, body map[string]string) *IncomingMessage {
	return &IncomingMessage{
		Client: client,
		Player: client.GetPlayer(),
		Body:   body,
	}
}

type Notification struct {
	MessageType string `json:"msg_type"`
}

type Response struct {
	MessageType string `json:"msg_type"`
	Successful  bool   `json:"success"`
	ResultCode  string `json:"result_code"`
}

type LoginResponse struct {
	Response
	Player *Player `json:"player"`
}

// handle an incoming login message
func (w *World) handleLogin(message *IncomingMessage) {
	// is this connection already authenticated?
	// see if we can find an existing player ..
	/*
		p := FindPlayerByClient(message.Client)
		if p != nil {
			// already authenticated, can't login again
			// TODO
			// note that this isn't really working; the same username can log on twice
			// instead the old player should be kicked and the new player take over
			p.Send(LoginResponse{
				Response: Response{
					MessageType: "login_response",
					Successful:  false,
					ResultCode:  "ALREADY_AUTHENTICATED",
				},
			})
			return
		}
	*/

	// todo authentication and stuff
	player := NewPlayer(message.Body["player_name"], message.Client)
	message.Client.SetPlayer(player)
	message.Player = player
	w.addPlayer(player)
	player.Send(LoginResponse{
		Response: Response{
			MessageType: "login_response",
			Successful:  true,
			ResultCode:  "OK",<commit_msg>handling more error cases for login<commit_after>package server

type IncomingMessage struct {
	Client Client
	Player *Player
	Body   map[string]string
}

func newIncomingMessage(client Client, body map[string]string) *IncomingMessage {
	return &IncomingMessage{
		Client: client,
		Player: client.GetPlayer(),
		Body:   body,
	}
}

type Notification struct {
	MessageType string `json:"msg_type"`
}

type Response struct {
	MessageType string `json:"msg_type"`
	Successful  bool   `json:"success"`
	ResultCode  string `json:"result_code"`
}

type LoginResponse struct {
	Response
	Player *Player `json:"player"`
}

// handle an incoming login message
func (w *World) handleLogin(message *IncomingMessage) {
	// is this connection already authenticated?
	// see if we can find an existing player ..
	if message.Client.GetPlayer() != nil {
		// you've already got one
		message.Client.Send(LoginResponse{
			Response:Response{
				MessageType:"login_response",
				Successful: false,
				ResultCode: "PLAYER_ALREADY_ATTACHED",
			},
		})
		return
	}
	// what if player is logged in on a different client?
	// TODO
	/*
		p := FindPlayerByClient(message.Client)
		if p != nil {
			// already authenticated, can't login again
			// TODO
			// note that this isn't really working; the same username can log on twice
			// instead the old player should be kicked and the new player take over
			p.Send(LoginResponse{
				Response: Response{
					MessageType: "login_response",
					Successful:  false,
					ResultCode:  "ALREADY_AUTHENTICATED",
				},
			})
			return
		}
	*/

	// todo authentication and stuff
	player := NewPlayer(message.Body["player_name"], message.Client)
	message.Client.SetPlayer(player)
	message.Player = player
	w.addPlayer(player)
	player.Send(LoginResponse{
		Response: Response{
			MessageType: "login_response",
			Successful:  true,
			ResultCode:  "OK",
{'fraction_non_alphanumeric': 0.1023391812865497, 'fraction_numerical': 0.0, 'mean_word_length': 3.9293948126801155, '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': '2594409', 'n_tokens_mistral': 1150, 'n_tokens_neox': 1028, 'n_words': 310}