public void BroadcastMessage() { lock (SocketService._broadcastLock) { this._isThreading = true; Fleck.IWebSocketConnection[] connections; System.Collections.Generic.Stack <Fleck.IWebSocketConnection> unavailable = null; this._connections.CopyTo(connections = new Fleck.IWebSocketConnection[this._connections.Count], 0); BufferItem item; while (this._broadcastBuffer.Count > 0) { item = this._broadcastBuffer.Dequeue(); if (DateTime.UtcNow.Subtract(item.TimeStamp).Milliseconds > 10000) { continue; } if (item.Message != null && item.Message.Length > 0) { foreach (Fleck.IWebSocketConnection client in connections) { if (client.IsAvailable == true) { if (client.ConnectionInfo.Path.Equals("/Listener") == true) { if (item.ConnectionId.Equals(client.ConnectionInfo.Id) == false) { client.Send(item.Message); } } } else { unavailable = new Stack <Fleck.IWebSocketConnection>(); unavailable.Push(client); } } } } if (unavailable != null) { while (unavailable.Count != 0) { this._connections.Remove(unavailable.Pop()); } } this._broadcastTimestamp = DateTime.UtcNow; this._isThreading = false; } }
///--------------------------------------------------------------------------------- /// Sever消息处理 ///--------------------------------------------------------------------------------- string loginAck(string msg, Socket serverSock) { msg += "MYSQLIP:" + "192.168.10.203" + "\r\n"; string status = TextFollowing(msg, "STATUS:"); if (status.Equals("OK")) { string operatorLevel = TextFollowing(msg, "OPERATORLEVEL:"); Fleck.IWebSocketConnection clientSock = myGlobals.ServerClient[serverSock]; string operatorName = myGlobals.operatorData.getOperatorName(clientSock); myGlobals.operatorData.setOperatorLevel(operatorName, operatorLevel); } return(msg); }
public override void HandleCommand(Fleck.IWebSocketConnection socket, RemoteConnectionInfo info, Room room) { if (room != null) { var videoInfos = room.Playlist.ToArray(); string message = "-- Start of playlist --\n"; for (int i = 0; i < videoInfos.Length; i++) { var videoId = videoInfos[i]; message += "[" + i + "]: " + videoId.VideoID + "\n"; } message += "-- End of playlist --"; info.SendChatMessage(message); } }
public FleckWebSocket(IWebSocketConnection connection) { _connection = connection; _connection.OnMessage = OnReceiveData; }
private void DashboardCommandReceived(string command, string data, bool single, Fleck.IWebSocketConnection source) { switch (command) { case DashboardBansMessage: { if (!single) { PluginBase.ApiServer.PushTo("Invalid command data.", "sysinfo", Structures.MessageFlag.ConsoleLogMessage, source); break; } lock (HighCourt.PermanentBans) { string response = $" Total bans : {HighCourt.PermanentBans.Count}\n"; if (HighCourt.PermanentBans.Count > 0) { //there are bans, so we add them to our message. foreach (var ban in HighCourt.PermanentBans) { response += " IPA : " + ban.Target.ToString() + $" / {ban.TargetName}\n"; } } PluginBase.ApiServer.PushTo(response, "sysinfo", Structures.MessageFlag.ConsoleLogMessage, source); } break; } case DashboardBanIpAddress: { if (single) { PluginBase.ApiServer.PushTo("Invalid command data.", "sysinfo", Structures.MessageFlag.ConsoleLogMessage, source); break; } if (IPAddress.TryParse(data, out IPAddress address)) { if (HighCourt.BanPlayer(address, source.ConnectionInfo.ClientIpAddress)) { PluginBase.ApiServer.Push( $"The target [{address}] has been banned permanently by {source.ConnectionInfo.ClientIpAddress}!", "(SERVER/CRITICAL/WIDE)", Structures.MessageFlag.ConsoleLogMessage); } else { PluginBase.ApiServer.PushTo("Could not find player.", Structures.ServerSources.DebugSystem, Structures.MessageFlag.ConsoleLogMessage, source); } } else { PluginBase.ApiServer.PushTo("Invalid command data.", "sysinfo", Structures.MessageFlag.ConsoleLogMessage, source); } break; } case DashboardBanIpAddressBlind: { if (single) { PluginBase.ApiServer.PushTo("Invalid command data.", "sysinfo", Structures.MessageFlag.ConsoleLogMessage, source); break; } if (IPAddress.TryParse(data, out IPAddress address)) { var report = new JusticeSystem.Report { Messages = new List <string> { "<adminsys / " + DateTime.Now + ">" }, Sources = new List <string> { source.ConnectionInfo.ClientIpAddress }, Target = address.ToString(), TargetName = "<unknown>", MinutesRemaining = 0, TotalReports = 0 }; HighCourt.AddPermBan(report); PluginBase.ApiServer.Push( $"The target [{address}] has been blindly banned by {source.ConnectionInfo.ClientIpAddress}!", "(SERVER/CRITICAL/WIDE)", Structures.MessageFlag.ConsoleLogMessage); } else { PluginBase.ApiServer.PushTo("Invalid command data.", "sysinfo", Structures.MessageFlag.ConsoleLogMessage, source); } break; } case DashboardUnBanAddress: { if (single) { PluginBase.ApiServer.PushTo("Invalid command data.", "sysinfo", Structures.MessageFlag.ConsoleLogMessage, source); break; } if (HighCourt.RemoveBan(data)) { PluginBase.ApiServer.PushTo($"The target player has been unbanned.", Structures.ServerSources.CommandSystem, Structures.MessageFlag.ConsoleLogMessage, source); PluginBase.ApiServer.Push( $"A player with the IP address [{data}] has been unbanned by {source.ConnectionInfo.ClientIpAddress}.", Structures.ServerSources.DebugSystemCritical, Structures.MessageFlag.ConsoleLogMessage); } else { PluginBase.ApiServer.PushTo($"Error: the target player [{data}] is not banned.", Structures.ServerSources.DebugSystem, Structures.MessageFlag.ConsoleLogMessage, source); } break; } case DashboardReloadBans: { if (!single) { PluginBase.ApiServer.PushTo("Invalid command data.", "sysinfo", Structures.MessageFlag.ConsoleLogMessage, source); break; } HighCourt.ReloadBans(); break; } } }
public void subscribe(Fleck.IWebSocketConnection socket) { subscribe(User.getUserFromSocket(socket)); }
public FleckWebSocket(IWebSocketConnection connection) { _connection = connection; _connection.OnMessage = OnReceiveData; }