Skip to content

Commit

Permalink
add feature to move/deaf/mute users #2
Browse files Browse the repository at this point in the history
  • Loading branch information
HarpyWar committed May 6, 2018
1 parent b829dd2 commit 8fba1e9
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 13 deletions.
51 changes: 41 additions & 10 deletions Murmur/VirtualServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,7 @@ public int AddChannel(string name, int parentId)
/// </summary>
/// <param name="channel"></param>
/// <param name="setAcl">add acls and groups?</param>
public void UpdateChannel(VirtualServerEntity.Channel channel, bool setAcl = false)
public void UpdateChannelState(VirtualServerEntity.Channel channel, bool setAcl = false)
{
// set channel info
var state = new Channel(channel.Id, channel.Name, channel.ParentId, channel.Links, channel.Description, false, channel.Position);
Expand Down Expand Up @@ -834,7 +834,7 @@ internal static VirtualServerEntity.OnlineUser getOnlineUser(User u)
Session = u.session,
Supress = u.suppress,
TcpOnly = u.tcponly,
#if MURMUR_124
#if MURMUR_123380
TcpPing = u.tcpPing,
UdpPing = u.udpPing,
#endif
Expand Down Expand Up @@ -994,7 +994,7 @@ public void UnregisterUser(int userId)


/// <summary>
/// Update exist user
/// Update registered user
/// </summary>
/// <param name="userId"></param>
/// <param name="user">with updated info</param>
Expand All @@ -1016,7 +1016,38 @@ public void UpdateUserInfo(VirtualServerEntity.User user)
_entity.Users.Add(user.Id, user);
}

/// <summary>
/// Update online user state (can be used to move/deaf/mute users)
/// </summary>
/// <param name="user"></param>
public void UpdateUserState(VirtualServerEntity.OnlineUser user)
{
// set user state
var state = new User(user.Session, user.Id, user.Mute, user.Deaf, user.Supress,
#if MURMUR_123
user.PrioritySpeaker,
#endif
user.SelfMute, user.SelfDeaf,
#if MURMUR_123
user.Recording,
#endif
user.ChannelId, user.Name, user.OnlineSecs, user.BytesPerSec, user.Version, user.Release,
user.Os, user.OsVersion, user.Identity, user.Context, user.Comment, user.Address, user.TcpOnly, user.Idlesecs
#if MURMUR_123380
,
user.UdpPing,
user.TcpPing
#endif
);

_server.setState(state);

// update in cache
if (_entity.OnlineUsers.ContainsKey(user.Id))
_entity.OnlineUsers[user.Id] = user;
else
_entity.OnlineUsers.Add(user.Id, user);
}

/// <summary>
/// Kick user from the server
Expand All @@ -1039,10 +1070,10 @@ public void KickUser(int sessionId, string reason)
}
}

#endregion
#endregion


#region BANS
#region BANS

/// <summary>
/// Flag to know if users was already loaded from remote or not
Expand Down Expand Up @@ -1112,7 +1143,7 @@ public void SetBans(SerializableDictionary<int, VirtualServerEntity.Ban> bans)
_entity.Bans = bans;
}

#endregion
#endregion


/// <summary>
Expand Down Expand Up @@ -1162,7 +1193,7 @@ private VirtualServerEntity.Tree _getTreeItem(Tree tree)
}


#region CALLBACKS
#region CALLBACKS

private Dictionary<string, object> callbacks = new Dictionary<string, object>();

Expand Down Expand Up @@ -1202,10 +1233,10 @@ public void RemoveCallback(string id = null)
}
}

#endregion
#endregion


#region IDisposable Support
#region IDisposable Support
private bool disposedValue = false; // To detect redundant calls

protected virtual void Dispose(bool disposing)
Expand Down Expand Up @@ -1240,7 +1271,7 @@ public void Dispose()
// GC.SuppressFinalize(this);
}

#endregion
#endregion
}


Expand Down
2 changes: 1 addition & 1 deletion Murmur/VirtualServerKeeper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ private bool _restoreEntity(VirtualServerEntity entity)
#if DEBUG
Console.WriteLine("[{0}][updating] channel #{1} {2}", server.Id, c.Key, c.Value.Name);
#endif
server.UpdateChannel(c.Value, true);
server.UpdateChannelState(c.Value, true);
}

// -- BANS
Expand Down
9 changes: 7 additions & 2 deletions MurmurPlugin/IVirtualServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -234,11 +234,11 @@ public interface IVirtualServer : IDisposable
int AddChannel(string name, int parentId);

/// <summary>
/// Update exist channel
/// Update exist channel (can be used to move channels)
/// </summary>
/// <param name="channel"></param>
/// <param name="setAcl">add acls and groups?</param>
void UpdateChannel(VirtualServerEntity.Channel channel, bool setAcl = false);
void UpdateChannelState(VirtualServerEntity.Channel channel, bool setAcl = false);

/// <summary>
/// Remove channel
Expand Down Expand Up @@ -294,6 +294,11 @@ public interface IVirtualServer : IDisposable
/// <param name="setAcl">add acls and groups?</param>
void UpdateUserInfo(VirtualServerEntity.User user);

/// <summary>
/// Update online user state (can be used to move/deaf/mute users)
/// </summary>
/// <param name="user"></param>
void UpdateUserState(VirtualServerEntity.OnlineUser user);

/// <summary>
/// Kick user from the server
Expand Down
29 changes: 29 additions & 0 deletions MurmurPlugin/VirtualServerEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,26 @@ public class OnlineUser
public bool TcpOnly;
public float UdpPing;
public int Version;

public void Move(IVirtualServer server, int newChannelId)
{
this.ChannelId = newChannelId;
server.UpdateUserState(this);
}
public void SetMute(IVirtualServer server, bool mute)
{
this.Mute = mute;
server.UpdateUserState(this);
}
public void SetDeafen(IVirtualServer server, bool deaf)
{
this.Deaf = deaf;
server.UpdateUserState(this);
}

}


public class Channel
{
public int Id;
Expand Down Expand Up @@ -117,6 +135,17 @@ public class Acl
public bool Inherited;
public int UserId;
}

public void Move(IVirtualServer server, int newParentId)
{
this.ParentId = newParentId;
server.UpdateChannelState(this);
}
public void SetName(IVirtualServer server, string newName)
{
this.Name = newName;
server.UpdateChannelState(this);
}
}

public class Tree
Expand Down

0 comments on commit 8fba1e9

Please sign in to comment.