Example #1
0
// GetBodyHandle implements the handle for the body document (GET).
func GetBodyHandle(newConn net.Conn, roomName, httpPayload string, rooms *config.CherryRooms, preprocessor *html.Preprocessor) {
	var userData map[string]string
	userData = rawhttp.GetFieldsFromGet(httpPayload)
	var validUser bool
	validUser = rooms.IsValidUserRequest(roomName, userData["user"], userData["id"], newConn)
	var replyBuffer []byte
	if !validUser {
		replyBuffer = rawhttp.MakeReplyBuffer(html.GetBadAssErrorData(), 404, true)
	} else {
		replyBuffer = rawhttp.MakeReplyBuffer(preprocessor.ExpandData(roomName, rooms.GetBodyTemplate(roomName)), 200, false)
	}
	newConn.Write(replyBuffer)
	if validUser {
		rooms.SetUserConnection(roomName, userData["user"], newConn)
	} else {
		newConn.Close()
	}
}