public String leaderElection(String ip) { Console.WriteLine(classNameLog + "Leader election on ip " + ip); //get machines Console.WriteLine(classNameLog + "Get machines"); Dictionary<int, String> machines = CSharpRpcServer.getMachines(); Console.WriteLine(machines); //get own ip and priority String myIp = CSharpRpcServer.getMyIpAddress(); int myPriority = CSharpRpcServer.getMyPriority(); Console.WriteLine(classNameLog + "My IP =>" + myIp + " My Priority => " + myPriority); Console.WriteLine(classNameLog + "Start Bully algorithm"); Bully bullyGenerator = new Bully(machines); bool iGaveUp = bullyGenerator.holdElection(myPriority); if (!iGaveUp) { //I'm the master, send message to all int newKeyMaster = myPriority; String newLeaderIp = CSharpRpcServer.setMaster(newKeyMaster); Console.WriteLine(classNameLog + "New Leader IP =>" + newLeaderIp + " New Leader Priority => " + newKeyMaster); Object[] parameters = new Object[] { newKeyMaster }; XmlRpcHelper.SendToAllMachines(machines, GlobalMethodName.setNewLeader, parameters); Console.WriteLine(classNameLog + "New leader notification send to all"); } //send new master to everyone return CSharpRpcServer.getIpMaster(); }
static void Main(string[] args) { var proxy = XmlRpcProxyGen.Create <IConnectionProxy>(); var port = NetworkHelper.FindFreePort(); var ipAddress = NetworkHelper.FindIp().ToString(); var nodeInfo = new NodeInfo(ipAddress, port); var electAlg = new Bully(nodeInfo, proxy); var ricartSyncAlgorithm = new RicartSyncAlgorithm(nodeInfo, proxy); var centralizedSyncAlgorithm = new CentralizedSyncAlgorithm(nodeInfo, proxy); var client = new Node(nodeInfo, proxy, electAlg, ricartSyncAlgorithm.Client, centralizedSyncAlgorithm.Client); var server = new Server(port, client, ricartSyncAlgorithm.Server, centralizedSyncAlgorithm.Server); var host = new Host(client, server); Console.WriteLine("Client IP: " + client.NodeInfo.GetIpAndPort()); Console.WriteLine("Client ID: " + client.NodeInfo.Id); while (true) { Console.Write("[" + client.NodeInfo.GetIpAndPort() + "] "); Console.WriteLine("The service is ready, please write commands: "); var command = Console.ReadLine(); try { client.ProcessCommand(command); } catch (Exception exception) { Console.WriteLine(exception.Message); } } }
public void RequestOutro() { //TODO: implement it if (OnOutroDone != null) { OnOutroDone(); } else { Bully.Log(""); } }
internal void ReportarAcosoMessage() { uint UserReportedId = Request.PopWiredUInt(); GameClient _client = OtanixEnvironment.GetGame().GetClientManager().GetClientByUserID(UserReportedId); // podemos usar esto para si está online uint RoomId = Request.PopWiredUInt(); var Room = OtanixEnvironment.GetGame().GetRoomManager().GetRoom(RoomId); if (Room == null) { return; } ServerMessage message = new ServerMessage(Outgoing.ReportAcosoMessage); if (_client != null && _client.GetHabbo() != null && _client.GetHabbo().GetChatMessageManager().messageCount <= 0) { message.AppendInt32(2); } else if (OtanixEnvironment.GetGame().GetModerationTool().UsersHasPendingTicket(Session.GetHabbo().Id) || OtanixEnvironment.GetGame().GetAlfaManager().GetBullyManager().UserStartedBully(Session.GetHabbo().Id)) { message.AppendInt32(3); } else { if (OtanixEnvironment.GetUnixTimestamp() - Session.GetHabbo().LastAlfaSend < 1200) { Session.GetMessageHandler().GetResponse().Init(Outgoing.onGuideSessionError); Session.GetMessageHandler().GetResponse().AppendInt32(0); Session.GetMessageHandler().SendResponse(); return; } Bully bully = new Bully(Session.GetHabbo().Id, UserReportedId, Room.GetChatMessageManager().GetRoomChatMessage()); if (!bully.SearchGuardian()) { bully.SerializeNoGuardians(); return; } OtanixEnvironment.GetGame().GetAlfaManager().GetBullyManager().AddBullie(bully); message.AppendInt32(0); } Session.SendMessage(message); }
//[OneTimeSetUp] public virtual void Init() { //if (initialized) Assert.Fail("fixture setup called multiple times"); if (initialized) { return; } initialized = true; var hostLookup = new Dictionary <String, Host>(); var mockProxy = new ConnectionProxyMock(hostLookup); for (var i = 0; i < HostNumber; i++) { //var proxy = XmlRpcProxyGen.Create<IConnectionProxy>(); var port = NetworkHelper.FindFreePort(); var ipAddress = NetworkHelper.FindIp().ToString(); var nodeInfo = new NodeInfo(ipAddress, port); var electAlg = new Bully(nodeInfo, mockProxy); var ricartSyncAlgorithm = new RicartSyncAlgorithm(nodeInfo, mockProxy); var centralizedSyncAlgorithm = new CentralizedSyncAlgorithm(nodeInfo, mockProxy); var client = new Node(nodeInfo, mockProxy, electAlg, ricartSyncAlgorithm.Client, centralizedSyncAlgorithm.Client); var server = new Server(port, client, ricartSyncAlgorithm.Server, centralizedSyncAlgorithm.Server); var host = new Host(client, server); hostLookup.Add(nodeInfo.GetFullUrl(), host); Hosts.Add(host); } //var proxy2 = XmlRpcProxyGen.Create<IConnectionProxy>(); var port2 = NetworkHelper.FindFreePort(); var ipAddress2 = "255.255.255.255"; var nodeInfo2 = new NodeInfo(ipAddress2, port2); var electAlg2 = new Bully(nodeInfo2, mockProxy); var ricartSyncAlgorithm2 = new RicartSyncAlgorithm(nodeInfo2, mockProxy); var centralizedSyncAlgorithm2 = new CentralizedSyncAlgorithm(nodeInfo2, mockProxy); var masterclient = new Node(nodeInfo2, mockProxy, electAlg2, ricartSyncAlgorithm2.Client, centralizedSyncAlgorithm2.Client); MasterHost = new Host(masterclient, new Server(port2, masterclient, ricartSyncAlgorithm2.Server, centralizedSyncAlgorithm2.Server)); hostLookup.Add(nodeInfo2.GetFullUrl(), MasterHost); }
internal void OnDisconnect() { try { if (Disconnected) { return; } Disconnected = true; if (Messenger != null) { Messenger.AppearOffline = true; Messenger.Destroy(); Messenger = null; } if (IsPremium()) { GetPremiumManager().Destroy(); } saveWardrobe(); SaveBadges(); //HabboEnvironment.GetGame().GetMuteManager().RemoveUserMute(Id); var pollParticipation = ""; if (this.PollParticipation.Count > 0) { foreach (UInt32 value in this.PollParticipation) { pollParticipation += value + ";"; } pollParticipation = pollParticipation.Remove(pollParticipation.Length - 1); } var votedRooms = ""; if (this.RatedRooms.Count > 0) { foreach (UInt32 value in this.RatedRooms) { votedRooms += value + ";"; } votedRooms = votedRooms.Remove(votedRooms.Length - 1); } var actrewards = ""; if (this.WiredRewards.Count > 0) { foreach (WiredActReward wrd in this.WiredRewards.Values) { actrewards += wrd.ItemId + "," + wrd.LastUpdate + "," + wrd.ActualRewards + "," + wrd.OriginalInt + ";"; } actrewards = actrewards.Remove(actrewards.Length - 1); } var navilogs = ""; if (this.navigatorLogs.Count > 0) { foreach (NaviLogs navi in this.navigatorLogs.Values) { navilogs += navi.Id + "," + navi.Value1 + "," + navi.Value2 + ";"; } navilogs = navilogs.Remove(navilogs.Length - 1); } var targetedoffers = ""; if (this.TargetedOffers.Count > 0) { foreach (KeyValuePair <uint, uint> k in this.TargetedOffers) { targetedoffers += k.Key + "-" + k.Value + ";"; } targetedoffers = targetedoffers.Remove(targetedoffers.Length - 1); } using (var dbClient = OtanixEnvironment.GetDatabaseManager().getQueryreactor()) { dbClient.setQuery("UPDATE users SET namechanges = '" + NameChanges + "', respect = '" + Respect + "', daily_respect_points = '" + DailyRespectPoints + "', daily_pet_respect_points = '" + DailyPetRespectPoints + "'," + " diamonds = '" + Diamonds + "', machine_last = @machineLast, currentquestid = '" + CurrentQuestId + "', block_trade = '" + ((BlockTrade) ? "1" : "0") + "'," + " block_newfriends = '" + ((HasFriendRequestsDisabled) ? "1" : "0") + "', look = @look, motto = @motto, gender = @gender, last_online = '" + LastOnline.ToString() + "'," + " achievement_points = '" + AchievementPoints + "', home_room = '" + HomeRoom + "', volumenSystem = '" + volumenSystem + "', prefer_old_chat = '" + ((preferOldChat) ? "1" : "0") + "'," + " last_purchase = '" + LastPurchase + "'," + " poll_participation = '" + pollParticipation + "', voted_rooms = '" + votedRooms + "'," + " lastfollowinglogin = '******', ignoreRoomInvitations = '" + ((IgnoreRoomInvitations) ? "1" : "0") + "'," + " citizenship_level = '" + CitizenshipLevel + "', helper_level = '" + HelperLevel + "', actrewards = '" + actrewards + "', dontfocususers = '" + ((DontFocusUser) ? "1" : "0") + "'," + " navilogs = @navilogs, targeted_offers = @targetedoffers, alertasAtivados = '" + ((alertasAtivados) ? "1" : "0") + "', frankJaApareceu = '" + ((frankJaApareceu) ? "1" : "0") + "', FavoriteGroup = '" + FavoriteGroup + "', moedas = '" + Moedas + "', corAtual = @coratual, coresjaTenho = '" + coresjaTenho + "', new_identity = '" + NewIdentity + "', new_bot = '" + NewBot + "', coins_purchased = '" + CoinsPurchased + "' WHERE id = " + Id); dbClient.addParameter("look", Look); dbClient.addParameter("coratual", corAtual); dbClient.addParameter("motto", Motto); dbClient.addParameter("gender", Gender); dbClient.addParameter("machineLast", MachineId); dbClient.addParameter("navilogs", navilogs); dbClient.addParameter("targetedoffers", targetedoffers); dbClient.runQuery(); dbClient.runFastQuery("DELETE FROM users_online WHERE user_id = '" + Id + "'"); } if (this.AlfaServiceEnabled) { if (this.AlfaGuideEnabled) { OtanixEnvironment.GetGame().GetAlfaManager().GetTourManager().RemoveAlfa(this.Id); this.AlfaGuideEnabled = false; } if (this.AlfaHelperEnabled) { Help help = null; if (OtanixEnvironment.GetGame().GetAlfaManager().GetHelpManager().Helps.ContainsKey(AlfaServiceId)) { help = OtanixEnvironment.GetGame().GetAlfaManager().GetHelpManager().Helps[AlfaServiceId]; } if (help != null) { if (help.helpState == HelpState.TALKING) { help.helpState = HelpState.FINISHED; } else if (help.helpState == HelpState.SEARCHING_USER) { help.NeedUpdate = true; } } OtanixEnvironment.GetGame().GetAlfaManager().GetHelpManager().RemoveAlfa(this.Id); this.AlfaHelperEnabled = false; } if (this.AlfaGuardianEnabled) { Bully bully = null; if (OtanixEnvironment.GetGame().GetAlfaManager().GetBullyManager().Bullies.ContainsKey(AlfaServiceId)) { bully = OtanixEnvironment.GetGame().GetAlfaManager().GetBullyManager().Bullies[AlfaServiceId]; } if (bully != null) { if (bully.bullyState == BullyState.WAITING_RESPONSE) { bully.bullySolution = BullySolution.EXIT; bully.bullyState = BullyState.FINISHED; } else if (bully.bullyState == BullyState.SEARCHING_USER) { bully.NeedUpdate = true; } } OtanixEnvironment.GetGame().GetAlfaManager().GetBullyManager().RemoveGuardian(this.Id); this.AlfaGuardianEnabled = false; } } if (InRoom && CurrentRoom != null && CurrentRoom.GetRoomUserManager() != null) { CurrentRoom.GetRoomUserManager().RemoveUserFromRoom(mClient, false, false, false); } if (AvatarEffectsInventoryComponent != null) { AvatarEffectsInventoryComponent.Dispose(); AvatarEffectsInventoryComponent = null; } if (InventoryComponent != null) { InventoryComponent.SetIdleState(); InventoryComponent.RunDBUpdate(); InventoryComponent.Destroy(); InventoryComponent = null; } if (BadgeComponent != null) { BadgeComponentLoaded = false; BadgeComponent.Destroy(); BadgeComponent = null; } if (RelationshipComposer != null) { RelationsLoaded = false; RelationshipComposer.Destroy(); RelationshipComposer = null; } if (Achievements != null && Achievements.Count > 0) { AchievementsLoaded = false; Achievements.Clear(); Achievements = null; } if (quests != null && quests.Count > 0) { QuestsLoaded = false; quests.Clear(); quests = null; } if (wardrobes != null && wardrobes.Count > 0) { WardrobeLoaded = false; wardrobes.Clear(); wardrobes = null; } if (clubManager != null) { clubManager.Clear(); clubManager = null; } if (sanctionManager != null) { sanctionManager.Clear(); sanctionManager = null; } } catch (Exception e) { Logging.LogCriticalException("Disconnecting user " + e); } finally { OtanixEnvironment.GetGame().GetClientManager().UnregisterClient(Id, Username); Logging.WriteLine(Username + " has logged out."); } }