Exemplo n.º 1
0
// GetExitHandle implements the handle for the exit document (GET).
func GetExitHandle(newConn net.Conn, roomName, httpPayload string, rooms *config.CherryRooms, preprocessor *html.Preprocessor) {
	var userData map[string]string
	var replyBuffer []byte
	userData = rawhttp.GetFieldsFromGet(httpPayload)
	if !rooms.IsValidUserRequest(roomName, userData["user"], userData["id"], newConn) {
		replyBuffer = rawhttp.MakeReplyBuffer(html.GetBadAssErrorData(), 404, true)
	} else {
		preprocessor.SetDataValue("{{.nickname}}", userData["user"])
		preprocessor.SetDataValue("{{.session-id}}", userData["id"])
		replyBuffer = rawhttp.MakeReplyBuffer(preprocessor.ExpandData(roomName, rooms.GetExitTemplate(roomName)), 200, true)
	}
	rooms.EnqueueMessage(roomName, userData["user"], "", "", "", rooms.GetExitMessage(roomName), "")
	newConn.Write(replyBuffer)
	rooms.RemoveUser(roomName, userData["user"])
	newConn.Close()
}