Пример #1
0
func FumbleLobbyCreated(lob *Lobby) error {
	if Fumble == nil {
		return nil
	}

	newLobby := mumble.NewLobby()
	newLobby.ID = int(lob.ID)

	lobby := new(mumble.Lobby)

	err := Fumble.Call("Fumble.CreateLobby", &newLobby, &lobby)

	if err != nil {
		helpers.Logger.Warning(err.Error())
		return err
	}
	FumbleLobbiesLock.Lock()
	defer FumbleLobbiesLock.Unlock()
	FumbleLobbies[lob.ID] = lobby

	return nil
}
Пример #2
0
func TestLobby(t *testing.T) {
	var err error

	// lobby
	l := mumble.NewLobby()
	l.ID = 123

	// user 1
	u1 := mumble.NewUser()
	u1.Name = "mariokid45"
	u1.Team = "RED"
	l.Players[u1.Name] = u1

	// bot for user 1
	b1 := NewBOT()
	b1.Config = bot_config
	b1.Config.Username = u1.Name
	b1.create()
	go b1.Connect()
	time.Sleep(2 * time.Second)

	// user 2
	u2 := mumble.NewUser()
	u2.Name = "bigkahuna"
	u2.Team = "BLU"
	l.Players[u2.Name] = u2

	// bot for user 2
	b2 := NewBOT()
	b2.Config = bot_config
	b2.Config.Username = u2.Name
	b2.create()
	go b2.Connect()
	time.Sleep(2 * time.Second)

	// create lobby
	err = client.Call("Fumble.CreateLobby", l, &l)
	assert.NoError(t, err)

	// args to disallow player 2 from joining lobby's mumble
	la := new(mumble.LobbyArgs)
	la.Lobby = l
	la.User = u2

	//////////////////////////////////////////////////
	//              *** IMPORTANT ***               //
	//////////////////////////////////////////////////
	// this pyroshit wont update the existing lobby //
	// variable, so i had to make a new one         //
	//////////////////////////////////////////////////
	var lobby *mumble.Lobby

	// Disallow player
	err = client.Call("Fumble.DisallowPlayer", la, &lobby)
	assert.NoError(t, err)

	// check if user 2 isn't in the player list
	assert.Nil(t, lobby.Players[u2.Name])

	// update the lobby variable in lobbyArgs
	la.Lobby = lobby

	// Allow player
	err = client.Call("Fumble.AllowPlayer", la, &lobby)
	assert.NoError(t, err)

	// check if both users are in the player list
	assert.NotNil(t, lobby.Players[u2.Name])

	var shouldNotBeMD mumble.MD

	// checks if the user is muted or deafened
	err = client.Call("Fumble.IsUserMD", u1, &shouldNotBeMD)
	assert.NoError(t, err)

	// check if user 1 is not muted or deafened
	assert.False(t, shouldNotBeMD.Muted)
	assert.False(t, shouldNotBeMD.Deafened)

	// mute and deaf the bot 1
	b1.Client.Self.SetSelfMuted(true)
	b1.Client.Self.SetSelfDeafened(true)

	// let the bot update
	time.Sleep(5 * time.Second)

	// redo the MD test
	var shouldBeMD mumble.MD

	// checks if the user is muted or deafened
	err = client.Call("Fumble.IsUserMD", u1, &shouldBeMD)
	assert.NoError(t, err)

	// check if user 1 is not muted or deafened
	assert.True(t, shouldBeMD.Muted)
	assert.True(t, shouldBeMD.Deafened)

	// end lobby
	err = client.Call("Fumble.EndLobby", lobby, &lobby)
	assert.NoError(t, err)
	assert.True(t, lobby.Channel.Temporary)
}