/// <summary> /// Handles the event for a new server joining the cluster. /// </summary> /// <param name="id">The id of the server joining.</param> /// <param name="remoteServer">The server joining.</param> protected void HandleServerJoinEvent(ushort id, IRemoteServer remoteServer) { EventHandler <ServerJoinedEventArgs> handler = ServerJoined; if (handler != null) { void DoServerJoinEvent() { long startTimestamp = Stopwatch.GetTimestamp(); try { handler?.Invoke(this, new ServerJoinedEventArgs(remoteServer, id, this)); } catch (Exception e) { serverJoinedEventFailuresCounter.Increment(); // TODO this seems bad, shoudln't we disconnect them? logger.Error("A plugin encountered an error whilst handling the ServerJoined event. The server will still be connected. (See logs for exception)", e); } double time = (double)(Stopwatch.GetTimestamp() - startTimestamp) / Stopwatch.Frequency; serverJoinedEventTimeHistogram.Report(time); } threadHelper.DispatchIfNeeded(DoServerJoinEvent); } }
private void SyncExistingComponentsToServer(IRemoteServer remoteServer) { foreach (ReadOnlyComponentDefinition compDef in ComponentRegistry.Instance.RegisteredComponents) { remoteServer.Connection["serverSync.registerComponentDefinition"]((ComponentDef)compDef); } }
/// <summary> /// Handles the event for a server leaving the cluster. /// </summary> /// <param name="id">The server leaving.</param> /// <param name="remoteServer">The server leaving.</param> protected void HandleServerLeaveEvent(ushort id, IRemoteServer remoteServer) { EventHandler <ServerLeftEventArgs> handler = ServerLeft; if (handler != null) { void DoServerLeaveEvent() { long startTimestamp = Stopwatch.GetTimestamp(); try { handler?.Invoke(this, new ServerLeftEventArgs(remoteServer, id, this)); } catch (Exception e) { serverLeftEventFailuresCounter.Increment(); logger.Error("A plugin encountered an error whilst handling the ServerLeft event. (See logs for exception)", e); } double time = (double)(Stopwatch.GetTimestamp() - startTimestamp) / Stopwatch.Frequency; serverLeftEventTimeHistogram.Report(time); } threadHelper.DispatchIfNeeded(DoServerLeaveEvent); } }
private void Server_DataReceived(IRemoteServer server, byte[] data) { lastServerHeartbeat = DateTime.UtcNow; foreach (var parsedData in NetworkDataParser.Parse(data)) { switch (parsedData.Type) { case NetworkDataType.Request: HandleRequest(parsedData as RequestData); break; case NetworkDataType.Heartbeat: // Last heartbeat time was set above. break; case NetworkDataType.LobbyData: UpdateLobbyData(parsedData as LobbyData); break; // TODO: other data default: // TODO: ignore? track safely? throw new ExceptionFreeserf("Unknown server data"); } } }
public GoogleDriveSystemItem(IRemoteServer server, FileMetadata_Info info, params IRemoteItem[] parent) : base(server, parent) { SetFileds(info); if (parent?.Length > 0) { isRoot = false; } }
void SyncExistingEntitiesToServer(IRemoteServer server) { foreach (var entity in World.Instance) { if (server.DoI.IsInterestedInEntity(entity)) { server.Connection["serverSync.addEntity"](entity.Guid, syncInfo[entity.Guid]); } } }
public LocalServer(IRemoteServer server, bool clientSideLoggingEnabled, string hostName) : base() { _server = server; _hostName = hostName; _referenceCount = 1; _internalServer = new Engine(); _internalServer.Name = Schema.Object.NameFromGuid(Guid.NewGuid()); _internalServer.LoggingEnabled = clientSideLoggingEnabled; _internalServer.Start(); _serverConnection = _server.Establish(_internalServer.Name, _hostName); _serverCacheTimeStamp = server.CacheTimeStamp; _clientCacheTimeStamp = 1; }
public RcloneCryptSystemItem(IRemoteServer server, IRemoteItem orgItem, params IRemoteItem[] parent) : base(server, parent) { if (!(parent?.Length > 0)) { isRoot = true; } orgpath = orgItem.FullPath; itemtype = orgItem.ItemType; size = ((orgItem.Size == null) ? orgItem.Size : CryptRclone.CalcDecryptedSize(orgItem.Size.Value)); modifiedDate = orgItem.ModifiedDate; createdDate = orgItem.CreatedDate; accessDate = orgItem.AccessDate; var encryptor = (_server as RcloneCryptSystem).Encrypter; if (encryptor.IsEncryptedName) { decryptedName = encryptor.DecryptName(orgItem.Name) ?? ""; if (decryptedName == "" && !isRoot) { throw new FileNotFoundException("filename dedoce error"); } } else { if (itemtype == RemoteItemType.Folder) { decryptedName = orgItem.Name; } else { if (orgItem.Name.EndsWith(CryptRclone.encryptedSuffix)) { decryptedName = orgItem.Name.Substring(0, orgItem.Name.Length - CryptRclone.encryptedSuffix.Length); } else { throw new FileNotFoundException("filename dedoce error"); } } } decryptedPath = OrgPathToPath(orgItem as RemoteItemBase); if (isRoot) { SetParent(this); } }
public void Start(string[] args) { ServerStaticData.Settings = ServerSettings.Instance; ServerStaticData.Initialize(); ProcessException.Handle("ServerStaticData.Initialize()"); if (ServerStaticData.Instance.ConfigFileErrors == string.Empty) { LogCollection logsCollection = new LogCollection(); TraceListenerToLogAdapter adapter = new TraceListenerToLogAdapter(logsCollection, TraceLevel.Info); object[] param = new object[] { ServerSettings.Instance }; string dllName = "ServerPrevalence"; string filePath = ServerEnvironment.Instance.GetFilePath(dllName + ".dll"); ObjectHandle objectHandle = null; try { objectHandle = Activator.CreateInstanceFrom(filePath, dllName + ".RemoteServer", true, BindingFlags.Instance | BindingFlags.Public, null, param, null, null, AppDomain.CurrentDomain.Evidence); } catch (TargetInvocationException ex) { ProcessException.Handle(ex.InnerException); Tracing.TraceErr(ex.InnerException); throw ex.InnerException; } catch (Exception e) { ProcessException.Handle(e); Tracing.TraceErr(e); throw e; } ProcessException.Handle("Server remoting object created."); server = (IRemoteServer)objectHandle.Unwrap(); server.Start(); this.started = true; } else { ProcessException.ErrorNotify.NotifyUser("Could not start server, there are errors in the config files. \n" + ServerStaticData.Instance.ConfigFileErrors); } }
public override void FixChain(IRemoteServer server) { try { _server = server; var orgItem = RemoteServerFactory.PathToItem(orgpath).Result; if (orgItem == null) { (_server as CarotCryptSystem)?.RemoveItem(ID); return; } decryptedPath = OrgPathToPath(orgItem as RemoteItemBase); decryptedName = (_server as CarotCryptSystem).CryptCarot.DecryptFilename(orgItem.Name) ?? ""; } catch { System.Diagnostics.Debug.WriteLine(ID); } base.FixChain(server); }
public CarotCryptSystemItem(IRemoteServer server, IRemoteItem orgItem, params IRemoteItem[] parent) : base(server, parent) { if (!(parent?.Length > 0)) { isRoot = true; } orgpath = orgItem.FullPath; itemtype = orgItem.ItemType; size = orgItem?.Size - (CryptCarotDAV.BlockSizeByte + CryptCarotDAV.CryptFooterByte + CryptCarotDAV.CryptFooterByte); modifiedDate = orgItem.ModifiedDate; createdDate = orgItem.CreatedDate; accessDate = orgItem.AccessDate; decryptedName = (_server as CarotCryptSystem).CryptCarot.DecryptFilename(orgItem.Name) ?? ""; decryptedPath = OrgPathToPath(orgItem as RemoteItemBase); if (isRoot) { SetParent(this); } }
private void Server_DataReceived(IRemoteServer server, byte[] data) { var parsedData = NetworkDataParser.Parse(data); switch (parsedData.Type) { case NetworkDataType.Request: HandleRequest(parsedData as RequestData); break; case NetworkDataType.Heartbeat: break; case NetworkDataType.LobbyData: UpdateLobbyData(parsedData as LobbyData); break; // TODO: other data default: // TODO: ignore? track safely? throw new ExceptionFreeserf("Unknown server data"); } }
public LocalSystemItem(IRemoteServer server, FileSystemInfo file, params IRemoteItem[] parent) : base(server, parent) { if (!(parent?.Length > 0)) { isRoot = true; } fullpath = file?.FullName; fullpath = ItemControl.GetOrgFilename(fullpath); if (!string.IsNullOrEmpty(fullpath)) { itemtype = (file.Attributes.HasFlag(FileAttributes.Directory)) ? RemoteItemType.Folder : RemoteItemType.File; modifiedDate = file.LastWriteTime; createdDate = file.CreationTime; accessDate = file.LastAccessTime; if (itemtype == RemoteItemType.File) { try { var info = new FileInfo(file.FullName); size = info.Length; } catch { } } } else { itemtype = RemoteItemType.Folder; fullpath = ""; } if (isRoot) { SetParent(this); } }
/// <summary> /// Creates a new ServerConnectedEventArgs from the given data. /// </summary> /// <param name="remoteServer">The <see cref="IRemoteServer"/> that connected.</param> public ServerConnectedEventArgs(IRemoteServer remoteServer) { this.RemoteServer = remoteServer; }
public override void FixChain(IRemoteServer server) { _server = server; base.FixChain(server); }
public AmazonDriveSystemItem(IRemoteServer server, FileMetadata_Info info, params IRemoteItem[] parent) : base(server, parent) { SetFileds(info); }
void SyncExistingEntitiesToServer(IRemoteServer server) { foreach (var entity in World.Instance) { if (server.DoI.IsInterestedInEntity(entity)) server.Connection["serverSync.addEntity"](entity.Guid, syncInfo[entity.Guid]); } }
/// <summary> /// Creates a new ServerDisconnectedEventArgs from the given data. /// </summary> /// <param name="remoteServer">The RemoteServer that disconnected.</param> /// <param name="error">The error that caused the disconnect.</param> /// <param name="exception">The exception that caused the disconenct.</param> public ServerDisconnectedEventArgs(IRemoteServer remoteServer, SocketError error, Exception exception) { this.RemoteServer = remoteServer; this.Exception = exception; this.Error = error; }
public ServerEventArgs(IRemoteServer server) { Server = server; }
void ProcessData(IRemoteServer server, INetworkData networkData, ResponseHandler responseHandler) { switch (networkData.Type) { case NetworkDataType.Request: HandleRequest(networkData as RequestData, responseHandler); break; case NetworkDataType.Heartbeat: { var heartbeat = networkData as Heartbeat; // Last heartbeat time was set before. if (PlayerIndex == 0u) { PlayerIndex = heartbeat.PlayerId; } foreach (var registeredHeartbeatHandler in registeredHeartbeatHandlers.ToArray()) { registeredHeartbeatHandler?.Invoke(heartbeat); } responseHandler?.Invoke(ResponseType.Ok); break; } case NetworkDataType.LobbyData: if (serverState != ServerState.Lobby) { responseHandler?.Invoke(ResponseType.BadState); } else { responseHandler?.Invoke(ResponseType.Ok); UpdateLobbyData(networkData as LobbyData); } break; case NetworkDataType.Response: { var responseData = networkData as ResponseData; foreach (var registeredResponseHandler in registeredResponseHandlers.ToArray()) { registeredResponseHandler?.Invoke(responseData); } break; } case NetworkDataType.InSync: { if (serverState != ServerState.Game && serverState != ServerState.Loading) { responseHandler?.Invoke(ResponseType.BadState); } else { if (Game == null) { serverState = ServerState.Offline; responseHandler?.Invoke(ResponseType.BadState); return; } try { var insyncData = networkData as InSyncData; Log.Verbose.Write(ErrorSystemType.Network, $"Processing in-sync message with game time {Misc.SecondsToTime(insyncData.GameTime)}."); if (!lastSavedGameStates.ContainsKey(insyncData.GameTime)) // We don't have the saved state anymore -> need full update { Log.Verbose.Write(ErrorSystemType.Network, $"Last saved game state with game time {Misc.SecondsToTime(insyncData.GameTime)} not available. Requesting re-sync."); RequestGameStateUpdate(); return; } Log.Verbose.Write(ErrorSystemType.Network, $"Updating last synced saved state to game time {Misc.SecondsToTime(insyncData.GameTime)} and discarding outdated saved game states."); lastVerifiedSavedGameState = lastSavedGameStates[insyncData.GameTime]; // Remove all outdated (timestamp before in-sync game time) saved states. foreach (var outdatedSavedGameState in lastSavedGameStates.Where(s => s.Key <= insyncData.GameTime).ToList()) { lastSavedGameStates.Remove(outdatedSavedGameState.Key); } } catch (Exception ex) { Log.Error.Write(ErrorSystemType.Network, "Failed to update game state: " + ex.Message); Disconnect(); throw ex; // TODO: Close game instead of crash? } } break; } case NetworkDataType.SyncData: { if (serverState != ServerState.Game && serverState != ServerState.Loading) { responseHandler?.Invoke(ResponseType.BadState); } else { if (Game == null) { serverState = ServerState.Offline; responseHandler?.Invoke(ResponseType.BadState); return; } try { var syncData = networkData as SyncData; #if DEBUG var stopWatch = System.Diagnostics.Stopwatch.StartNew(); Log.Verbose.Write(ErrorSystemType.Network, "Processing sync ... "); #endif lock (Game) { lastSavedGameStates.Clear(); if (lastVerifiedSavedGameState == null) { lastVerifiedSavedGameState = SavedGameState.FromGame(Game); } lastVerifiedSavedGameState = SavedGameState.UpdateGameAndLastState(Game, lastVerifiedSavedGameState, syncData.SerializedData, syncData.Full); } #if DEBUG Log.Verbose.Write(ErrorSystemType.Network, $"Processing sync done in {stopWatch.ElapsedMilliseconds / 1000.0} seconds"); #endif } catch (Exception ex) { Log.Error.Write(ErrorSystemType.Network, "Failed to update game state: " + ex.Message); Disconnect(); throw ex; // TODO: Close game instead of crash? } } break; } default: // Should have been handled by Server_DataReceived already. break; } }
void Server_DataReceived(IRemoteServer server, byte[] data) { Log.Verbose.Write(ErrorSystemType.Network, $"Received {data.Length} byte(s) of data from server '{server.Ip}'."); lastServerHeartbeat = DateTime.UtcNow; if (NetworkDataReceiver == null) { Log.Error.Write(ErrorSystemType.Application, "Network data receiver is not set up."); Disconnect(); return; } if (serverState == ServerState.Offline) { serverState = ServerState.Lobby; } try { foreach (var parsedData in NetworkDataParser.Parse(data)) { Log.Verbose.Write(ErrorSystemType.Network, $"Received {parsedData.LogName} (message index {parsedData.MessageIndex})."); switch (parsedData.Type) { case NetworkDataType.Heartbeat: // Last heartbeat time was set above. if (parsedData.MessageIndex != Global.SpontaneousMessage) { // If it has a message index, it is an answer to a heartbeat request. NetworkDataReceiver.Receive(server, parsedData, null); } break; case NetworkDataType.Request: case NetworkDataType.LobbyData: case NetworkDataType.SyncData: NetworkDataReceiver.Receive(server, parsedData, (ResponseType responseType) => SendResponse(parsedData.MessageIndex, responseType)); break; case NetworkDataType.Response: case NetworkDataType.InSync: NetworkDataReceiver.Receive(server, parsedData, null); break; case NetworkDataType.UserActionData: Log.Error.Write(ErrorSystemType.Network, "User actions can't be send to a client."); SendResponse(parsedData.MessageIndex, ResponseType.BadDestination); break; default: Log.Error.Write(ErrorSystemType.Network, "Received unknown server data."); SendResponse(parsedData.MessageIndex, ResponseType.BadRequest); break; } } } catch (Exception ex) { Log.Error.Write(ErrorSystemType.Network, "Error in receiving server data: " + ex.Message); } }
// Token: 0x06000012 RID: 18 RVA: 0x0000303C File Offset: 0x0000123C private void btnLogin_Click(object sender, EventArgs e) { if (this.txtExamCode.Text.Trim().Equals("")) { MessageBox.Show("Please provide an Exam code"); } else if (this.txtUser.Text.Trim().Equals("")) { MessageBox.Show("Please provide an username"); } else if (this.txtPassword.Text.Trim().Equals("")) { MessageBox.Show("Please provide a password"); } else if (this.txtDomain.Text.Trim().Equals("")) { MessageBox.Show("Please provide a domain address"); } else { try { string url = string.Concat(new object[] { "tcp://", this.si.IP, ":", this.si.Port, "/Server" }); IRemoteServer remoteServer = (IRemoteServer)Activator.GetObject(typeof(IRemoteServer), url); RegisterData registerData = new RegisterData(); registerData.Login = this.txtUser.Text; registerData.Password = this.txtPassword.Text; registerData.ExamCode = this.txtExamCode.Text; registerData.Machine = Environment.MachineName.ToUpper(); EOSData eosdata = remoteServer.ConductExam(registerData); if (eosdata.Status == RegisterStatus.EXAM_CODE_NOT_EXISTS) { MessageBox.Show("Exam code is not available!", "Start exam", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else if (eosdata.Status == RegisterStatus.FINISHED) { MessageBox.Show("The exam is finished!", "Start exam", MessageBoxButtons.OK, MessageBoxIcon.Hand); } else if (eosdata.Status == RegisterStatus.REGISTERED) { MessageBox.Show("This user [" + this.txtUser.Text + "] is already registered. Need re-assign to continue the exam.", "Exam Registering", MessageBoxButtons.OK, MessageBoxIcon.Hand); } else if (eosdata.Status == RegisterStatus.REGISTER_ERROR) { MessageBox.Show("Register ERROR, try again", "Exam Registering", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else if (eosdata.Status == RegisterStatus.NOT_ALLOW_MACHINE) { MessageBox.Show("Your machine is not allow to take the exam!", "Exam Registering", MessageBoxButtons.OK, MessageBoxIcon.Hand); } else if (eosdata.Status == RegisterStatus.NOT_ALLOW_STUDENT) { MessageBox.Show("The account is NOT allow to take the exam!", "Exam Registering", MessageBoxButtons.OK, MessageBoxIcon.Hand); } else if (eosdata.Status == RegisterStatus.LOGIN_FAILED) { MessageBox.Show("Sorry, unable to verify your information. Check [User Name] and [Password]!", "Login failed"); } if (eosdata.Status == RegisterStatus.NEW || eosdata.Status == RegisterStatus.RE_ASSIGN) { base.Hide(); eosdata.GUI = GZipHelper.DeCompress(eosdata.GUI, eosdata.OriginSize); Assembly assembly = Assembly.Load(eosdata.GUI); Type type = assembly.GetType("ExamClient.frmEnglishExamClient"); Form form = (Form)Activator.CreateInstance(type); IExamclient examclient = (IExamclient)form; eosdata.GUI = null; eosdata.ServerInfomation = this.si; eosdata.RegData = registerData; examclient.SetExamData(eosdata); form.Show(); } } catch (Exception ex) { MessageBox.Show("Start Exam Error:\nCannot connect to the EOS server!\n", "Connecting...", MessageBoxButtons.OK, MessageBoxIcon.Hand); } } }
/// <summary> /// Creates new event args. /// </summary> /// <param name="remoteServer">The server that left.</param> /// <param name="id">The ID of the server that left.</param> /// <param name="serverGroup">The group the server left.</param> public ServerLeftEventArgs(IRemoteServer remoteServer, ushort id, IServerGroup serverGroup) { this.RemoteServer = remoteServer; this.ID = id; this.ServerGroup = serverGroup; }
private void SyncExistingComponentsToServer(IRemoteServer remoteServer) { foreach (ReadOnlyComponentDefinition compDef in ComponentRegistry.Instance.RegisteredComponents) remoteServer.Connection["serverSync.registerComponentDefinition"]((ComponentDef)compDef); }
/// <summary> /// Creates a new args object for the <see cref="IRemoteServer.MessageReceived"/> event. /// </summary> /// <param name="message">The message received.</param> /// <param name="sendMode">The send mode the message was received with.</param> /// <param name="remoteServer">The server the message was received from.</param> public static ServerMessageReceivedEventArgs Create(Message message, SendMode sendMode, IRemoteServer remoteServer) { ServerMessageReceivedEventArgs messageReceivedEventArgs = ServerObjectCache.GetServerMessageReceivedEventArgs(); messageReceivedEventArgs.message = message; messageReceivedEventArgs.SendMode = sendMode; messageReceivedEventArgs.RemoteServer = remoteServer; messageReceivedEventArgs.isCurrentlyLoungingInAPool = false; return(messageReceivedEventArgs); }