private IInputPeer GetPeer(int id, PeerType peerType) { switch (peerType) { case (PeerType.Channal): { return(new TInputPeerChannel() { ChannelId = id, }); } case (PeerType.Chat): { return(new TInputPeerChat() { ChatId = id }); } case (PeerType.User): { return(new TInputPeerUser() { UserId = id }); } default: { throw new NotImplementedException($"{peerType} not implemented"); } } }
public override void OnClientError(NetworkConnection conn, int errorCode) { base.OnClientError(conn, errorCode); peerType = PeerType.None; Logs.AddLog("OnClientError"); }
public async Task Job(int peerId, PeerType peerType) { await _commandDispatcher.DispatchAsync(new CreateJob.Command() { UserId = _userProvider.UserId(User), PeerId = peerId, PeerType = peerType }); }
private static void IncomingMessageTypeDebugMessage(PeerType t, NetIncomingMessage message) { //Only received when compiled in DEBUG mode. var str = message.ReadString(); str = Enum.GetName(typeof(PeerType), t) + ": " + str; Debug.Log(str); DebugConsole.Instance.Log(str); }
public bool IsConnectionPeerType(NetworkConnection conn, PeerType peertype) { if (conn == null) { return(false); } var cid = conn.connectionId; var strkey = MsgType.MsgTypeToString(MsgType.PeerType); return(peerinfo.ContainsKey(cid) && peerinfo[cid].ContainsKey(strkey) && (PeerType)peerinfo[cid][strkey] == peertype); }
public override void OnClientConnect(NetworkConnection conn) { base.OnClientConnect(conn); peerType = PeerType.Client; Logs.AddLog("OnClientConnect"); ProcessMgr.enabled = true; }
public override void OnStopServer() { base.OnStopServer(); peerType = PeerType.None; Logs.AddLog("OnStopServer"); SceneManager.UnloadSceneAsync("MainUI"); }
public override void OnClientDisconnect(NetworkConnection conn) { base.OnClientDisconnect(conn); peerType = PeerType.None; Logs.AddLog("OnClientDisconnect"); ProcessMgr.enabled = false; }
public ProtocolHeader() { this._targetType = PeerType.PEER_TYPE_DEFAULT; this.__isset.targetType = true; this._sourceType = PeerType.PEER_TYPE_CLIENT; this.__isset.sourceType = true; this._serializeType = SerializeType.SERIALIZE_TYPE_THRIFT; this.__isset.serializeType = true; this._closeSocket = false; this.__isset.closeSocket = true; }
// TODO WHEN IS IT SELF? public LC(int id, string firstName, string lastName, ChatPhoto photo) { ID = id; FirstName = firstName; LastName = lastName; Type = PeerType.Chat; if (photo != null) { LoadIfl(photo); } }
public override void OnStartServer() { base.OnStartServer(); peerType = PeerType.Server; Logs.AddLog("OnStartServer"); SceneManager.LoadScene("MainUI", LoadSceneMode.Additive); OptionPanel.Display(false); }
//Save a step when handling network events. /// <summary> /// Add callback for a message received /// </summary> /// <param name="recipient">event Received by Client or Server?</param> /// <param name="e"></param> /// <param name="callback"></param> public void AddIncomingEventHandler(PeerType recipient, NetworkEvents.Event e, IncomingMessageDelegate callback) { switch (recipient) { case PeerType.Server: OnClientMessageReceived += (s, message) => { message.RunEvent(e, PeerType.Client, callback); }; break; case PeerType.Client: OnServerMessageReceived += (s, message) => { message.RunEvent(e, PeerType.Server, callback); }; break; } }
public List <NetworkConnection> GetPeerTypeConnection(PeerType peertype) { var peertypeconnection = new List <NetworkConnection>(); foreach (var c in NetworkServer.connections) { if (IsConnectionPeerType(c, peertype)) { peertypeconnection.Add(c); } } return(peertypeconnection); }
public bool IsPeerTypeConnected(PeerType peertype, int[] excludeconns) { foreach (var cid in peerinfo.Keys.Except(excludeconns)) { var pi = peerinfo[cid]; var strkey = MsgType.MsgTypeToString(MsgType.PeerType); if (pi != null && pi.ContainsKey(strkey) && (PeerType)pi[strkey] == peertype) { return(true); } } return(false); }
private void IncomingMessageTypeStatusChanged(PeerType t, NetIncomingMessage message) { // ReSharper disable once SwitchStatementMissingSomeCases switch (message.SenderConnection.Status) { case NetConnectionStatus.Connected: OnClientConnected?.Invoke(t, message.SenderConnection); break; case NetConnectionStatus.Disconnecting: OnClientDisonnect?.Invoke(t, message.SenderConnection); break; } }
private static void IncomingMessageTypeDefault(PeerType t, NetIncomingMessage message) { try { var msg = string.Format("Network: Unhandled Message Type: \n\t{0}\n\t{1}", message.MessageType, message.ReadString()); Debug.Log(msg); DebugConsole.Instance.Log(msg); } catch (Exception) { /*ignored*/ } }
private void IncomingMessageTypeData(PeerType receiver, NetIncomingMessage message) { if (receiver == PeerType.Client) { OnServerMessageReceived?.Invoke(receiver, message); } else if (receiver == PeerType.Server) { OnClientMessageReceived?.Invoke(receiver, message); } else { throw new ArgumentOutOfRangeException(nameof(receiver), "Invalid NetPeer class."); } }
public StartupResult StartServer(string address, ushort port, ushort max_connections = 32, bool insecure = false) { if (pointer == IntPtr.Zero) { return(StartupResult.FAILED_TO_CREATE_NETWORK_THREAD); } StartupResult = RakPeer_Native.NET_StartServer(pointer, address, port, max_connections, insecure); if (StartupResult == StartupResult.RAKNET_STARTED) { Type = PeerType.Server; is_shutteddown = false; } return(StartupResult); }
public ConnectionAttemptResult StartClient(string address, ushort port, string password = "", short attempts = 10) { if (pointer == IntPtr.Zero) { return(ConnectionAttemptResult.INVALID_CONNECT_PARAMETER); } ConnectionAttemptResult = RakPeer_Native.NET_StartClient(pointer, address, port, password, attempts); if (ConnectionAttemptResult == ConnectionAttemptResult.CONNECTION_ATTEMPT_STARTED) { Type = PeerType.Client; is_shutteddown = false; } return(ConnectionAttemptResult); }
public BtnAutoSoftphone(PeerType objLocalPeerType, string uri, ModulePermissions[] MyPermissions, string Role) { try { VMuktiAPI.VMuktiHelper.RegisterEvent("SignOut").VMuktiEvent += new VMuktiEvents.VMuktiEventHandler(BtnAutoSoftphone_VMuktiEvent); this.abc = new UserControl(); InitializeComponent(); dialer = new ctlDialer(objLocalPeerType, uri, MyPermissions, Role); this.abc = dialer; this.abc.Background = Brushes.SteelBlue; } catch (Exception ex) { VMuktiAPI.VMuktiHelper.ExceptionHandler(ex, "BtnAutoSoftphone()", "BtnSoftphone.xaml.cs"); } }
/// <summary> /// Spawns a task in our database pool to write an activity into the user activity history table /// </summary> /// <param name="userId">Id of the user corresponding to this event</param> /// <param name="playerId">Id of the player corresponding to this event</param> /// <param name="ip">Ip of the client corresponding to this event</param> /// <param name="peer">Peer type that raised this event, client or editor</param> /// <param name="action">User action taken to be logged</param> /// <param name="meta">Any extra metadata/notes for this event</param> public static void LogActivity(Guid userId, Guid playerId, string ip, PeerType peer, UserAction action, string meta) { if (Options.Instance.Logging.UserActivity) { DbInterface.Pool.QueueWorkItem(new Action <UserActivityHistory>(Log), new UserActivityHistory { TimeStamp = DateTime.UtcNow, UserId = userId, PlayerId = playerId, Ip = ip ?? "", Peer = peer, Action = action, Meta = meta, }); } }
public PipeStream(string name, FileAccess mode) { name = name?.Trim(); if (string.IsNullOrEmpty(name)) { name = null; } else if (!name.StartsWith(PREFIX, StringComparison.OrdinalIgnoreCase)) { name = PREFIX + name; } _readHandle = _writeHandle = IntPtr.Zero; _peerType = PeerType.Client; Name = name; Open(mode); }
public void RemovePeer(TorrentPeer peer, byte[] hash, PeerType type = PeerType.Seeder) { var db = RedisBacking.GetDatabase(); string insert = peer.StringPeer(); var stringHash = Unpack.Hex(hash); //ResetHash(stringHash); db.SetRemove("t:" + Unpack.Hex(hash), insert); if (type == PeerType.Seeder) { db.StringDecrement("s:" + Unpack.Hex(hash)); } else { db.StringDecrement("l:" + Unpack.Hex(hash)); } }
public async Task ForPeer(int id, PeerType peerType, string userId, int offset, int maxId) { IInputPeer peer = GetPeer(id, peerType); IClientApi client = await _telegramService.BuildAsync(userId); IMessages history = await TelegramRequest.HandleAsync(() => { return(client.MessagesService.GetHistoryAsync(peer, offset, maxId, 100)); }); List <Message> messages = MessagesParser.Parse(history, id, peerType); await _eventHub.SendAsync(messages); if (messages.Count > 0) { BackgroundJob.Schedule <GetMessages>( job => job.ForPeer(id, peerType, userId, offset + 100, 0), TimeSpan.FromSeconds(_randomService.Random.Next(5, 20))); } }
public void AddPeer(TorrentPeer peer, byte[] hash, PeerType type = PeerType.Seeder) { var db = RedisBacking.GetDatabase(); string insert = peer.StringPeer(); var stringHash = Unpack.Hex(hash); //ResetHash(stringHash); db.SetAdd("t:" + stringHash, insert); if (type == PeerType.Seeder) { db.StringIncrement("s:" + stringHash); //amount of seeders } else { db.StringIncrement("l:" + stringHash); //amount of leechers } }
public LC(Chat chat) { if (chat is ChatConstructor) { var c = (ChatConstructor)chat; ID = c.id; FirstName = c.title; LastName = string.Empty; AccessHash = 0; Username = string.Empty; Type = PeerType.Chat; Phone = string.Empty; LoadIfl(c.photo); } }
public LC(User user, bool selfUser = false) { if (user is UserConstructor) { var u = (UserConstructor)user; ID = u.id; if (u.access_hash.HasValue) { AccessHash = u.access_hash.Value; } Username = u.username; Type = selfUser ? PeerType.Self : PeerType.User; FirstName = u.first_name; LastName = u.last_name; Phone = u.phone; LoadIfl(u.photo); } }
/// <summary> /// Initializes the network classes, but doesn't establish connection. /// </summary> /// <param name="peerType">Client, Server or Both.</param> /// <param name="port"></param> public void InitNetwork(PeerType peerType, int?port = 1777) { InitializeMessageLoopActions(); this.LocalPeerType = peerType; switch (this.LocalPeerType) { case PeerType.Client: var npConfig = new NetPeerConfiguration(AppName); client = new NetClient(npConfig); break; case PeerType.Server: serverConfiguration = new NetPeerConfiguration(AppName); if (port != null) { serverConfiguration.Port = (int)port; } server = new NetServer(serverConfiguration); break; case PeerType.Both: serverConfiguration = new NetPeerConfiguration(AppName); var cConfig = new NetPeerConfiguration(AppName); cConfig.Port = (int)port + 1; client = new NetClient(cConfig); if (port != null) { serverConfiguration.Port = (int)port; } server = new NetServer(serverConfiguration); server.Start(); break; default: throw new ArgumentOutOfRangeException(nameof(this.LocalPeerType), this.LocalPeerType, null); } OnInitialized?.Invoke(this.LocalPeerType); }
protected NamedPipeStream() { _handle = IntPtr.Zero; _mode = (FileAccess)0; _peerType = PeerType.Server; }
public NamedPipeStream(IntPtr handle, FileAccess mode) { _handle = handle; _mode = mode; _peerType = PeerType.Client; }
public NamedPipeStream(string pipename, FileAccess mode) { _handle = IntPtr.Zero; _peerType = PeerType.Client; Open(pipename, mode); }
protected NamedPipeStream(SafeFileHandle handle, FileAccess access, bool isAsync) : base(handle, access, 0x8000, isAsync) { this.FPeerType = PeerType.Client; }
public NamedPipeStream(string pipeName, FileAccess access) : base(Windows.CreateFile(pipeName, access, FileShare.None, IntPtr.Zero, FileMode.Open, FileOptions.None, IntPtr.Zero), access) { this.FPeerType = PeerType.Client; }
public void SendToAll(PeerType type, MMCMessage message) { foreach (KeyValuePair<ClientValue, NetConnection> kv in this.ConnectedClients) { if (kv.Key.Value[0] == type.ToString()) this.SendMessage(message, kv.Value); } }
public MMCPeerConfig(NetPeerConfiguration config, PeerType tp, string n) { npConfig = config; type = tp; name = n; }
public ctlDesktop_Sharing(PeerType PeerType, string uri, ModulePermissions[] MyPermissions, string Role) { try { InitializeComponent(); thGlobalVariable = new System.Threading.Thread(new System.Threading.ThreadStart(GlobalVariable)); thGlobalVariable.Start(); bgHostService = new BackgroundWorker(); VMuktiAPI.VMuktiHelper.RegisterEvent("SignOut").VMuktiEvent += new VMuktiEvents.VMuktiEventHandler(ctlDesktop_Sharing_VMuktiEvent); //objGetUserList = new DelGetUserList(objDelGetUserList); //objDelSendMsg = new DelSendMessage(delSendMessage); //objRemoveUser = new DelRemoveUser(delRemoveUser); //objDelGetMsg = new DelGetMessage(delGetMessage); //objDisAllowView = new DelDisAllowView(delDisAllowView); //objStopControl = new DelStopControl(delStopControl); myMouseInput.type = INPUT_MOUSE; KeyBoardTimer.Interval = new TimeSpan(0, 0, 0, 0, 0); KeyBoardTimer.Tick += new EventHandler(KeyBoardTimer_Tick); objFullWindow.txtInp.PreviewKeyDown += new KeyEventHandler(txtInp_PreviewKeyDown); btnView.Tag = 0; btnControl.Tag = 0; this.Loaded += new RoutedEventHandler(ctlDesktop_Sharing_Loaded); btnView.Click += new RoutedEventHandler(btnView_Click); btnControl.Click += new RoutedEventHandler(btnControl_Click); // ThrHostDesktop = new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(HostDesktopService)); bgHostService.DoWork += new DoWorkEventHandler(bgHostService_DoWork); List<object> lstParams = new List<object>(); lstParams.Add(PeerType); lstParams.Add(uri); lstParams.Add(MyPermissions); // ThrHostDesktop.Start(lstParams); bgHostService.RunWorkerAsync(lstParams); } catch (Exception ex) { VMuktiHelper.ExceptionHandler(ex, "ctlDesktop_Sharing", "ctlDesktop_Sharing.xaml.cs"); } }