Exemplo n.º 1
0
func (Lobby) RequestLobbyListData(so *wsevent.Client, _ struct{}) interface{} {
	var lobbies []models.Lobby
	db.DB.Where("state = ?", models.LobbyStateWaiting).Order("id desc").Find(&lobbies)
	so.EmitJSON(helpers.NewRequest("lobbyListData", models.DecorateLobbyListData(lobbies)))

	return chelpers.EmptySuccessJS
}
Exemplo n.º 2
0
func (Lobby) RequestLobbyListData(_ *wsevent.Server, so *wsevent.Client, data []byte) []byte {
	var lobbies []models.Lobby
	db.DB.Where("state = ?", models.LobbyStateWaiting).Order("id desc").Find(&lobbies)
	list, _ := json.Marshal(models.DecorateLobbyListData(lobbies))
	so.EmitJSON(helpers.NewRequest("lobbyListData", string(list)))

	return chelpers.EmptySuccessJS
}
Exemplo n.º 3
0
func AfterConnect(server *wsevent.Server, so *wsevent.Client) {
	server.AddClient(so, fmt.Sprintf("%s_public", config.GlobalChatRoom)) //room for global chat

	var lobbies []models.Lobby
	err := db.DB.Where("state = ?", models.LobbyStateWaiting).Order("id desc").Find(&lobbies).Error
	if err != nil {
		logrus.Error(err)
		return
	}

	so.EmitJSON(helpers.NewRequest("lobbyListData", models.DecorateLobbyListData(lobbies)))
	chelpers.BroadcastScrollback(so, 0)
	so.EmitJSON(helpers.NewRequest("subListData", models.DecorateSubstituteList()))
}
Exemplo n.º 4
0
func RequestLobbyListData(so socketio.Socket) func(string) string {
	return func(s string) string {
		var lobbies []models.Lobby
		db.DB.Where("state = ?", models.LobbyStateWaiting).Order("id desc").Find(&lobbies)
		list, err := models.DecorateLobbyListData(lobbies)
		if err != nil {
			helpers.Logger.Warning("Failed to send lobby list: %s", err.Error())
		} else {
			so.Emit("lobbyListData", list)
		}

		resp, _ := chelpers.BuildSuccessJSON(simplejson.New()).Encode()
		return string(resp)
	}
}
Exemplo n.º 5
0
func AfterConnect(so socketio.Socket) {
	so.Join(fmt.Sprintf("%s_public", config.Constants.GlobalChatRoom)) //room for global chat

	var lobbies []models.Lobby
	err := db.DB.Where("state = ?", models.LobbyStateWaiting).Order("id desc").Find(&lobbies).Error
	if err != nil {
		helpers.Logger.Critical("%s", err.Error())
		return
	}

	list, err := models.DecorateLobbyListData(lobbies)
	if err != nil {
		helpers.Logger.Critical("Failed to send lobby list: %s", err.Error())
		return
	}

	so.Emit("lobbyListData", list)
	BroadcastScrollback(so, 0)
}
Exemplo n.º 6
0
func AfterConnect(server *wsevent.Server, so *wsevent.Client) {
	server.AddClient(so, fmt.Sprintf("%s_public", config.Constants.GlobalChatRoom)) //room for global chat

	var lobbies []models.Lobby
	err := db.DB.Where("state = ?", models.LobbyStateWaiting).Order("id desc").Find(&lobbies).Error
	if err != nil {
		helpers.Logger.Critical("%s", err.Error())
		return
	}

	bytes, _ := json.Marshal(models.DecorateLobbyListData(lobbies))
	if err != nil {
		helpers.Logger.Critical("Failed to send lobby list: %s", err.Error())
		return
	}

	so.EmitJSON(helpers.NewRequest("lobbyListData", string(bytes)))
	BroadcastScrollback(so, 0)
	bytes, _ = json.Marshal(helpers.NewRequestFromObj("subListData", models.GetSubList()))
	so.EmitJSON(helpers.NewRequest("subListData", string(bytes)))
}