public static void ProposeSyncCamera(User user) { // Sync this user's camera with me if (!Simulator.Instance.Sdk.IsConnected) return; //var camera = GetCurrentCameraReplay(); var camera = GetCurrentCameraSessionTime(); var users = new List<User>(); users.Add(user); var command = SyncCommandHelper.ProposeSyncCameras(users, camera); SyncManager.Instance.SendCommand(command); }
private SyncManager(Dispatcher dispatcher) { _dispatcher = dispatcher; _offlineUser = new User(); _offlineUser.IsRegistered = true; _offlineUser.CustId = 0; _offlineUser.Name = "Local"; _offlineUser.ShortName = "L"; _offlineUser.UserColor = UserColor.Offline; _offlineUser.IsHost = true; _status = ConnectionStatus.Disconnected; _state = new SyncState(0); _users = new UserContainerCollection(); _users.Add(new UserContainer(_offlineUser)); }
private void RegisterUser(UserContext context, SyncCommand command) { // Client is trying to register // Find his connection and link it to a new user var conn = FindConnection(context); if (conn != null) { if (!conn.IsRegistered) { var id = (int)command.Data.Id; var ssid = (long)command.Data.Ssid; var name = command.Data.Name.ToString(); var shortname = command.Data.ShortName.ToString(); var password = command.Data.Password.ToString(); // Check password if (password == _password) { // Check subsession ID if (ssid == _subSessionId) { // Check name length if (!string.IsNullOrWhiteSpace(name) && name.Length >= MIN_NAME_LENGTH) { // Try to find previously connected user var user = this.State.Users.FromId(id); if (user == null) { // New user user = new User(); user.CustId = id; this.State.Users.Add(user); UserColors.SetColor(user); } if (!user.IsConnected) { user.Name = name; user.ShortName = shortname; user.IsRegistered = true; user.IsConnected = true; user.IsHost = id == _adminId; // Link him to his connection conn.User = user; this.OnLog("User registered: " + name); var response = new SyncResponse(SyncResponse.ResponseTypes.Connect); response.Data = new { Success = true, User = user }; this.Reply(context, response); this.BroadcastUserlist(); this.SendState(context); } else { this.OnLog("Already connected: " + name); this.FailRegistration(context, "You are already connected."); } } else { this.OnLog("Name too short: " + name); this.FailRegistration(context, string.Format("Please choose a name with a minimum of {0} characters.", MIN_NAME_LENGTH)); } } else { this.OnLog("Incorrect session ID."); this.FailRegistration(context, "Incorrect subsession ID: you must join the same session as the server host."); } } else { this.OnLog("Incorrect password attempt: " + password); this.FailRegistration(context, "Incorrect password."); } } else { this.OnLog("Already registered: " + conn.Username); this.FailRegistration(context, "You are already registered."); } } else { this.OnLog("Unknown client tried to register: " + context.ClientAddress); this.FailRegistration(context, "Unknown client."); } }
private UserConnection FindConnection(User user) { var id = user.CustId; return _connections.FirstOrDefault(c => c.IsRegistered && c.User.CustId == id); }
public UserContainer(User user) { this.User = user; }
public static void CountColor(User user) { if (user.UserColor != null) { var color = _colors.SingleOrDefault(c => c.Order == user.UserColor.Order); if (color != null) color.Count += 1; } }
public static void SetColor(User user) { // Sort by count, then by order var colors = _colors.OrderBy(c => c.Count).ThenBy(c => c.Order); var color = colors.First(); color.Count += 1; user.UserColor = color; }
public static void SyncCamera(User user) { // Sync to other camera // Obtain camera details }
public static LiveAdminUser FromUser(User user) { return new LiveAdminUser() { Id = user.CustId, Name = user.Name, ShortName = user.ShortName }; }
private void ResetStatus() { _name = string.Empty; _password = string.Empty; _status = ConnectionStatus.Disconnected; _user = null; _dispatcher.Invoke(() => _users.Clear()); }
private void HandleRegistration(UserContext context, SyncResponse response, TaskCompletionSource<ConnectionResult> tcs) { if (response.Data.Success.Value) { // Registered successfully _status = ConnectionStatus.Connected; this.RaiseConnected(); _user = (User) JsonConvert.DeserializeObject<User>(response.Data.User.ToString()); //_user.Context = context; tcs.SetResult(new ConnectionResult()); } else { // Failed this.ResetStatus(); tcs.SetResult(new ConnectionResult(response.Data.Message.Value)); } }