Exemple #1
0
func requestStart(users []string, realm channels.Realm) { // All request start.
	doneCh := make(chan string, len(users))
	for _, user := range users {
		go func(user string) {
			msg := channels.Message{
				Data:  "start",
				Mtype: channels.MessageType(TableMT),
				From:  user,
			}
			msg.SetRealm(realm)
			MessageHandler.HandleMessage(msg)
			doneCh <- user
		}(user)
	}
	for i := 0; i < len(users); i++ {
		// Drain the channel.
		log.Printf("[DEBUG] Draining %s\n", <-doneCh)
	}
}
Exemple #2
0
func guessWords(users []string, realm channels.Realm) {
	countdown := time.NewTimer(time.Second * (time.Duration(CountdownTime) + 1))
	<-countdown.C
	words := []string{"ROAMINGS", "APIMANIA", "OPPUGNER", "LATHERED",
		"MIDWIVES", "COLORFUL", "SEAWEEDS", "LIKEABLY", "HALTERED", "BLINDAGE",
		"REEDITED", "SETIFORM", "BOUNDARY", "TRENCHES", "FINAGLED", "MOTHBALL",
		"BARRACKS", "TERAPHIM", "MOUCHING", "UPCOMING", "UNFETTER", "FLUTTERY",
		"VERITIES", "SUNDECKS", "SEESAWED", "RIVIERES", "EUPHRASY", "GHARIALS",
		"SHAMMING", "KIDNAPER", "FOILISTS", "CHURNERS", "QUINTALS", "EXPENSES",
		"KIPPERER", "DECENTLY", "CAMISOLE", "IMMESHED", "UNSTACKS", "CUMQUATS",
		"BEQUESTS", "ORGANISM", "HUGGIEST", "EPONYMIC", "HITHERTO", "VOLPLANE",
		"HUISACHE", "RIFFRAFF", "QUOINING", "ANTIHERO", "OUTSMOKE", "SEAWARES",
		"STOPPLED"}
	// Have all users guess all words.
	doneCh := make(chan string, len(users)*len(words))
	for _, word := range words {
		for _, user := range users {

			go func(user string, word string) {
				msg := channels.Message{
					Data:  word,
					Mtype: channels.MessageType(GuessMT),
					From:  user,
				}
				msg.SetRealm(realm)
				MessageHandler.HandleMessage(msg)
				doneCh <- user
			}(user, word)

		}
	}
	for i := 0; i < len(users)*len(words); i++ {
		<-doneCh
	}

}
Exemple #3
0
func (m wwMessageHandler) HandleMessage(msg channels.Message) {
	log.Println("[DEBUG] Got a message", msg.Data, msg.Mtype,
		msg.From, msg.Realm())
	switch MessageType(msg.Mtype) {
	case TableMT:
		log.Println("[DEBUG] Got a table command.")
		handleTableMessage(msg.Data, msg.Realm(), msg.From, m.webolith,
			m.sender)

	case GuessMT:
		handleGuess(msg.Data, msg.Realm(), msg.From, m.sender)
	}
}