Ejemplo n.º 1
0
// check if user is registered
func TestIsUserRegistered(t *testing.T) {
	var reply bool

	u := mumble.NewUser()
	u.Name = username

	if err := client.Call("Fumble.IsUserRegistered", u, &reply); err != nil {
		log.Fatal(err)
	}

	assert.False(t, reply)
}
Ejemplo n.º 2
0
// find user by info
func TestFindUserByInfo(t *testing.T) {
	u := mumble.NewUser()
	u.Name = username

	if err := client.Call("Fumble.FindUserByInfo", u, &u); err != nil {
		log.Fatal(err)
	}

	b := bot.Client.Users.Find(username)

	assert.Equal(t, u.Name, username)
	if b.Stats != nil && u.IP != "<nil>" {
		assert.NotNil(t, u.IP)
		assert.Equal(t, u.IP, b.Stats.IP.String())
	}

	t.Log(u)
}
Ejemplo n.º 3
0
// checks if the bot can join a channel
// that hes not allowed to get into
// and also checks if he can get in
// when allowed
func TestAllowUserIntoChannel(t *testing.T) {
	var nr mumble.NoReply
	var err error
	args := new(mumble.Args)

	u := mumble.NewUser()
	u.CopyInfo(bot.Client.Users.Find(username))
	args.User = u

	c := mumble.NewChannel()
	c.Name = channelName
	args.Channel = c

	err = client.Call("Fumble.AllowUser", args, &nr)
	assert.NoError(t, err)

	bot.Client.Self.Move(bot.Client.Channels.Find(channelName))

	var nr2 mumble.NoReply
	err = client.Call("Fumble.DisallowUser", args, &nr2)
	assert.NoError(t, err)
}
Ejemplo n.º 4
0
func FumbleAllowPlayer(lobbyId uint, playerName string, playerTeam string) error {
	if Fumble == nil {
		return nil
	}

	user := mumble.NewUser()
	user.Name = playerName
	user.Team = mumble.Team(playerTeam)

	FumbleLobbiesLock.Lock()
	defer FumbleLobbiesLock.Unlock()

	reply := new(mumble.Lobby)

	err := Fumble.Call("Fumble.AllowPlayer", &mumble.LobbyArgs{user, FumbleLobbies[lobbyId]}, reply)
	if err != nil {
		helpers.Logger.Warning(err.Error())
	}
	FumbleLobbiesLock.Lock()
	defer FumbleLobbiesLock.Unlock()
	FumbleLobbies[lobbyId] = reply
	return nil
}
Ejemplo n.º 5
0
func TestKickUser(t *testing.T) {
	var nr mumble.NoReply
	var err error

	u := mumble.NewUser()
	u.CopyInfo(bot.Client.Users.Find(username))

	kick := new(mumble.KickArgs)
	kick.User = u
	kick.Reason = "too elite"

	err = client.Call("Fumble.KickUser", kick, &nr)
	assert.NoError(t, err)

	time.Sleep(3 * time.Second)

	var isUserConnecTed bool
	err = client.Call("Fumble.IsUserConnected", u, &isUserConnecTed)
	assert.NoError(t, err)
	assert.False(t, isUserConnecTed)

	go bot.Connect()
	time.Sleep(3 * time.Second)
}
Ejemplo n.º 6
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)
}
Ejemplo n.º 7
0
// check if the user is connecTed
// it tests by all available values: UserID, Hash, IP and Name
func TestIsUserConnected(t *testing.T) {
	u := mumble.NewUser()
	u.Name = username

	var reply bool = false

	// just to make sure the bot connects
	ticker := time.NewTicker(1 * time.Second)
	for _ = range ticker.C {
		if !reply {
			if err := client.Call("Fumble.IsUserConnected", u, &reply); err != nil {
				log.Fatal(err)
			}
		} else {
			ticker.Stop()
			break
		}
	}
	t.Log("Bot connected")

	// tries all available types of
	// checking if the user is connected
	for i := 0; i < 3; i++ {
		var r bool
		u = mumble.NewUser()

		switch i {
		case 0: // Username
			u.Name = username
		case 1: // UserID
			uid := int(bot.Client.Users.Find(username).UserID)

			if uid != 0 {
				t.Log("UserID: " + strconv.Itoa(uid))
				u.UserID = uid
			}

			// "true" so the test doesn't fail
			// if the userid is 0
			r = true
		case 2: // Hash
			h := bot.Client.Users.Find(username).Hash

			if h != "" {
				t.Log("Hash: " + h)
				u.Hash = h
			}

			// "true" so the test doesn't fail
			// if no hash is found
			r = true
		case 3: // IP
			u.IP = bot.Client.Users.Find(username).Stats.IP.String()
		}

		// ignore nil hash (non-registered user)
		if !r {
			if err := client.Call("Fumble.IsUserConnected", u, &r); err != nil {
				log.Fatal(err)
			}

			assert.True(t, r)
		}
	}

	t.Log("IsUserConnected? " + strconv.FormatBool(reply))
}