public void SendPrivateTest() { Thread serverThread = new Thread(() => { try { Server.Network network = new Server.Network("127.0.0.1", 5009); NetworkUser user = null; while (user == null) { user = Server.Network.AddUser(); } Player player = new Player(0, Team.FIRST, user); Network.SendPrivate(player, "this is a test"); } catch (Exception) { Assert.False(true); } }); Thread clientThread = new Thread(() => { try { Server.NetworkUser server = new Server.NetworkUser((new TcpClient("127.0.0.1", 5009)).Client); String str = server.GetReader().ReadLine(); Assert.Equal(str, "this is a test"); } catch (Exception) { Assert.False(true); } }); try { serverThread.Start(); Thread.Sleep(5000); clientThread.Start(); } catch (UserQuit) { Console.WriteLine("Test ok"); } catch (Exception) { Console.WriteLine("Something happened..."); } }
public void AddUserTest() { Thread serverThread = new Thread(() => { try { Server.Network network = new Server.Network("127.0.0.1", 5006); NetworkUser user = null; while (user == null) { user = Server.Network.AddUser(); } Assert.NotNull(user); } catch (Exception) { Assert.False(true); } }); Thread clientThread = new Thread(() => { try { Server.NetworkUser server = new Server.NetworkUser((new TcpClient("127.0.0.1", 5006)).Client); } catch (Exception) { Assert.False(true); } }); try { serverThread.Start(); Thread.Sleep(5000); clientThread.Start(); } catch (UserQuit) { Console.WriteLine("Test ok"); } catch (Exception) { Console.WriteLine("Something happened..."); } }
static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Idle += ApplicationIdle; DbManager.Initialize(Properties.Settings.Default.Nuri4ConnectionString); ActiveServerForm = new ServerForm(); Log.Reporter = ActiveServerForm.ActiveLogForm; ApplicationContext = new ApplicationContext(); ApplicationContext.MainForm = ActiveServerForm; Socket = new Network(); Application.Run(ApplicationContext); }
static void Main(string[] args) { Log.Module = Module; robotFolder = Path.GetDirectoryName(Application.ExecutablePath); motionsFolder = string.Format("{0}\\Motions", robotFolder); audioFolder = string.Format("{0}\\Audio", robotFolder); networkBusy = false; // There is no network traffic between server and client. bool newStart = true; // kan misschien weg. Log.WriteLineMessage("=================================="); Log.WriteLineMessage("Roboard KHR-1HV Server Application"); Log.WriteLineMessage("=================================="); Network mainServer = new Network(); Log.WriteLineMessage("Checking folder structure"); // Does the Motions folder exists? if (!Directory.Exists(motionsFolder)) { Log.WriteLineFail("Motions folder exist"); // If not lets create one. Directory.CreateDirectory(motionsFolder); Log.WriteLineSucces("Motions folder created"); // Delete the Table.ini since all the motions are gone, // lets create a new Table.ini File.Delete(string.Format("{0}\\Table.ini",robotFolder)); Log.WriteLineSucces("Deleting existing Table.ini"); } else Log.WriteLineSucces("Motions folder exist"); // Does the Audio folder exists? if (!Directory.Exists(audioFolder)) { Log.WriteLineFail("Audio folder exist"); // If not lets create one Directory.CreateDirectory(audioFolder); Log.WriteLineSucces("Audio folder created"); } else Log.WriteLineSucces("Audio folder exist"); if (!Server.MainIni.Open) Server.MainIni.Init(); if (!Server.Table.Open) Server.Table.Init(); if (!Server.Trim.Open) Server.Trim.Init(); if (MainIni.EnableRemoteControl) if (!Server.XBox360.Open) Server.XBox360.Init(); // RCServo.Close(); RCServo.Init(); Server.I2C.Init(); Server.SPI.Init(); Server.AD7918.Init(); Server.MotionInterpreter.Init(); // Check if start-up motion is set // and play that motion // if (Server.MainIni.PowerUpMotion != -1) { Log.WriteLineMessage(string.Format("Play startup motion: {0}", Server.MainIni.PowerUpMotion)); } // remember that the voltage needs to be divided by 10; Listen(mainServer); // function call to start listening for connections. while (newStart) { //Network.messageHandler += new Network.NewMessageEventHandler(mainServer_messageHandler); infinteLoop = true; while (infinteLoop) { // networkbusy werkt niet meer door de threading. Dit moet opgelost worden door // 1-of de networkbusy ook te laten afhangen van playingdone. // in iedergeval moet er in de motioninterpreter een property komen die laat zien dat // de motion playing is of niet. // 2-of in de xbox360controller een stop en start. if (!networkBusy) { // for real time mixing, read the sensor and do the calculations // and apply them to the current servo position with mixwidth as sensorvalue. Server.XBox360.ControllerState(); if (Server.XBox360.Open) { //if (Server.XBox360.Buttons == 128) //{ // Server.MotionInterpreter.playing = false; // //newStart = false; // break; //} if (Server.XBox360.Buttons == 64) { if (RCServo.Connected) RCServo.Close(); else RCServo.Init(); Thread.Sleep(1000); } for (int i = 0; i < StaticUtilities.numberOfMotions; i++) { // check if the button pressed is linked to a motion in the table and // that the controller state is not 65535 (no motion). if ((Convert.ToInt32(Table.MotionTable["Motion" + (i + 1).ToString()]["Control"]) == Server.XBox360.Buttons) && (Server.XBox360.Buttons != 65535)) { Log.WriteLineMessage(string.Format("Playing motion: {0}, {1}", Table.MotionTable["Motion" + (i + 1).ToString()]["Name"], Table.MotionTable["Motion" + (i + 1).ToString()]["Control"])); Server.MotionInterpreter.Filename = Server.Table.MotionTable["Motion" + (i + 1).ToString()]["Filename"]; Server.MotionInterpreter.Play(); break; } } // END For } // END If } // END If } // END While } // END While AD7918.Close(); SPI.Close(); I2C.Close(); RCServo.Close(); mainServer.StopListening(); Log.WriteLineMessage("Exit"); Application.Exit(); }
static void Listen(Network mainServer) { // Start listening for connections mainServer.StartListening(); // Show that we started to listen for connections Log.WriteLineMessage("Monitoring for connections..."); Network.messageHandler += new Network.NewMessageEventHandler(mainServer_messageHandler); }
public override void OnResponse(Network.NetState sender, RelayInfo info) { if (m_Strip == null || m_Strip.Deleted) return; if (m_Viewer == null || m_Viewer.Deleted || !m_Viewer.Alive) return; if (m_Strip.RootParentEntity != m_Viewer) { m_Viewer.SendMessage("That must be in your backpack for you to edit it."); return; } switch (info.ButtonID) { case (int)PrayerButton.Accept: { m_Strip.Prayer.SetName(info.GetTextEntry((int)PrayerText.Name).Text); m_Strip.Name = m_Strip.Prayer.Name; m_Strip.Prayer.Emote = info.GetTextEntry((int)PrayerText.Emote).Text; m_Strip.Prayer.Speech = info.GetTextEntry((int)PrayerText.Speech).Text; m_Strip.Prayer.Message = info.GetTextEntry((int)PrayerText.TargetMessage).Text; int val = 0; if (ValidateInt(info.GetTextEntry((int)PrayerText.Intensity).Text, ref val)) m_Strip.Prayer.Intensity = val; if (ValidateInt(info.GetTextEntry((int)PrayerText.Seconds).Text, ref val)) m_Strip.Prayer.Duration = val; if (ValidateInt(info.GetTextEntry((int)PrayerText.Range).Text, ref val)) m_Strip.Prayer.Range = val; if (ValidateInt(info.GetTextEntry((int)PrayerText.Area).Text, ref val)) m_Strip.Prayer.Area = val; if (ValidateInt(info.GetTextEntry((int)PrayerText.Repetitions).Text, ref val)) m_Strip.Prayer.Repetitions = val; if (ValidateInt(info.GetTextEntry((int)PrayerText.Delay).Text, ref val)) m_Strip.Prayer.RepetitionDelay = val; if (ValidateInt(info.GetTextEntry((int)PrayerText.SoundID).Text, ref val)) m_Strip.Prayer.SoundID = val; if(info.ButtonID != (int)PrayerButton.Accept) SendNewGump(); return; } case (int)PrayerButton.Clear: { return; } case (int)PrayerButton.PrevEffect: { if (m_Strip.Prayer.Effect == PrayerEffect.Strength) m_Strip.Prayer.Effect = PrayerEffect.DefendChance; else { m_Strip.Prayer.Effect--; } goto case (int)PrayerButton.Accept; } case (int)PrayerButton.NextEffect: { if (m_Strip.Prayer.Effect == PrayerEffect.DefendChance) m_Strip.Prayer.Effect = PrayerEffect.Strength; else { m_Strip.Prayer.Effect++; } goto case (int)PrayerButton.Accept; } case (int)PrayerButton.PrevComponent: { int index = CustomFaithSpell.ValidComponents.IndexOf(m_Strip.Prayer.Component); if (index == 0) m_Strip.Prayer.Component = CustomFaithSpell.ValidComponents[CustomFaithSpell.ValidComponents.Count - 1]; else m_Strip.Prayer.Component = CustomFaithSpell.ValidComponents[index - 1]; goto case (int)PrayerButton.Accept; } case (int)PrayerButton.NextComponent: { int index = CustomFaithSpell.ValidComponents.IndexOf(m_Strip.Prayer.Component); if (index == CustomFaithSpell.ValidComponents.Count - 1) m_Strip.Prayer.Component = CustomFaithSpell.ValidComponents[0]; else m_Strip.Prayer.Component = CustomFaithSpell.ValidComponents[index + 1]; goto case (int)PrayerButton.Accept; } default: break; } base.OnResponse(sender, info); }
public void SendNetworksTest() { Thread serverThread = new Thread(() => { try { Server.Network network = new Server.Network("127.0.0.1", 5003); List <NetworkUser> users = new List <NetworkUser>(); NetworkUser user = null; while (user == null) { user = Server.Network.AddUser(); } users.Add(user); user = null; while (user == null) { user = Server.Network.AddUser(); } users.Add(user); Network.SendNetworks(users, "this is a test"); } catch (Exception) { Assert.False(true); } }); Thread clientThread = new Thread(() => { try { Server.NetworkUser server = new Server.NetworkUser((new TcpClient("127.0.0.1", 5003)).Client); Assert.Equal(server.GetReader().ReadLine(), "this is a test"); } catch (Exception) { Assert.False(true); } }); Thread clientThread2 = new Thread(() => { try { Server.NetworkUser server = new Server.NetworkUser((new TcpClient("127.0.0.1", 5003)).Client); Assert.Equal(server.GetReader().ReadLine(), "this is a test"); } catch (Exception) { Assert.False(true); } }); try { serverThread.Start(); Thread.Sleep(5000); clientThread.Start(); clientThread2.Start(); } catch (UserQuit) { Console.WriteLine("Test ok"); } catch (Exception) { Console.WriteLine("Something happened..."); } }
public override void OnResponse(Network.NetState sender, RelayInfo info) { if (m_Emp == null || m_Emp.Deleted || !m_Emp.Alive || m_Emp.IsDeadBondedPet || m_Emp.IsDeadPet) return; switch (info.ButtonID) { case (int)EmpButton.Cancel: return; case (int)EmpButton.Okay: { if (m_Emp == null || m_Emp.Deleted || !m_Emp.Alive || m_Emp.IsDeadBondedPet || m_Emp.IsDeadPet) return; if (m_Viewer == null || m_Viewer.Deleted || !m_Viewer.Alive) return; if (!m_Emp.IsSlave) { int val = 0; if (ValidateInt(m_Viewer, info.GetTextEntry(1).Text, "Wage", ref val)) { if (val < 1) val = 1; m_Emp.Wage = val; } } return; } case (int)EmpButton.PreviousRes: { if (m_Emp == null || m_Emp.Deleted || !m_Emp.Alive || m_Emp.IsDeadBondedPet || m_Emp.IsDeadPet) return; if (m_Viewer == null || m_Viewer.Deleted || !m_Viewer.Alive) return; if (!m_Emp.IsSlave) { int val = 0; if (ValidateInt(m_Viewer, info.GetTextEntry(1).Text, "Wage", ref val)) { if (val < 1) val = 1; m_Emp.Wage = val; } } if(m_Emp.HeldResources > 0) m_Emp.WithdrawResources(m_Viewer, m_Emp.HeldResources); int index = 0; for (int i = 0; i < ResourceList.Count; i++) { if (ResourceList[i] == m_Emp.ToGather) { index = i; continue; } } if (index == 0) { m_Emp.ToGather = ResourceList[ResourceList.Count - 1]; } else { m_Emp.ToGather = ResourceList[index - 1]; } m_Viewer.SendGump(new EmployeeGump(m_Viewer, m_Emp)); return; } case (int)EmpButton.NextRes: { if (m_Emp == null || m_Emp.Deleted || !m_Emp.Alive || m_Emp.IsDeadBondedPet || m_Emp.IsDeadPet) return; if (m_Viewer == null || m_Viewer.Deleted || !m_Viewer.Alive) return; if (!m_Emp.IsSlave) { int val = 0; if (ValidateInt(m_Viewer, info.GetTextEntry(1).Text, "Wage", ref val)) { if (val < 1) val = 1; m_Emp.Wage = val; } } if (m_Emp.HeldResources > 0) m_Emp.WithdrawResources(m_Viewer, m_Emp.HeldResources); int index = 0; for (int i = 0; i < ResourceList.Count; i++) { if (ResourceList[i] == m_Emp.ToGather) { index = i; continue; } } if (index == ResourceList.Count - 1) { m_Emp.ToGather = ResourceList[0]; } else { m_Emp.ToGather = ResourceList[index + 1]; } m_Viewer.SendGump(new EmployeeGump(m_Viewer, m_Emp)); return; } case (int)EmpButton.WithdrawRes: { if (m_Emp == null || m_Emp.Deleted || !m_Emp.Alive || m_Emp.IsDeadBondedPet || m_Emp.IsDeadPet) return; if (m_Viewer == null || m_Viewer.Deleted || !m_Viewer.Alive) return; m_Viewer.Prompt = new WithdrawResourcePrompt(m_Emp); m_Viewer.SendMessage("Enter an amount to withdraw from your employee."); return; } default: return; } base.OnResponse(sender, info); }
public override void OnResponse(Network.NetState sender, RelayInfo info) { if (info.ButtonID < (int)GroupButton.Remove) { switch (info.ButtonID) { case (int)GroupButton.Cancel: { return; } case (int)GroupButton.Okay: { int val = 0; if (ValidateInt(info.GetTextEntry((int)GroupText.ResetTime).Text, ref val)) GroupInfo.SetResetTime(val, m_Group.Leader); GroupInfo.SetGroupName(info.GetTextEntry((int)GroupText.Name).Text, m_Group.Leader); if (!GroupInfo.Groups.Contains(m_Group)) GroupInfo.Groups.Add(m_Group); return; } case (int)GroupButton.Clear: { m_Viewer.SendMessage("Clearing your group..."); GroupInfo.ClearGroup(m_Group.Leader); m_Viewer.SendMessage("Group cleared!"); m_Viewer.SendGump(new GroupGump(m_Viewer, m_Group, m_Current)); return; } case (int)GroupButton.ChangeLeader: { m_Viewer.Target = new ChangeGroupLeaderTarget(m_Group); m_Viewer.SendMessage("Target a player to make them the new leader of this group."); return; } case (int)GroupButton.AddMember: { int val = 0; if (ValidateInt(info.GetTextEntry((int)GroupText.ResetTime).Text, ref val)) GroupInfo.SetResetTime(val, m_Group.Leader); GroupInfo.SetGroupName(info.GetTextEntry((int)GroupText.Name).Text, m_Group.Leader); if (!GroupInfo.Groups.Contains(m_Group)) GroupInfo.Groups.Add(m_Group); m_Viewer.Target = new AddToGroupTarget(m_Group); m_Viewer.SendMessage("Target an NPC to add them to your group."); return; } case (int)GroupButton.ScrollUp: { int val = 0; if (ValidateInt(info.GetTextEntry((int)GroupText.ResetTime).Text, ref val)) GroupInfo.SetResetTime(val, m_Group.Leader); GroupInfo.SetGroupName(info.GetTextEntry((int)GroupText.Name).Text, m_Group.Leader); if (!GroupInfo.Groups.Contains(m_Group)) GroupInfo.Groups.Add(m_Group); if (m_Current > 0) m_Current--; m_Viewer.SendGump(new GroupGump(m_Viewer, m_Group, m_Current)); return; } case (int)GroupButton.ScrollDown: { int val = 0; if (ValidateInt(info.GetTextEntry((int)GroupText.ResetTime).Text, ref val)) GroupInfo.SetResetTime(val, m_Group.Leader); GroupInfo.SetGroupName(info.GetTextEntry((int)GroupText.Name).Text, m_Group.Leader); if (!GroupInfo.Groups.Contains(m_Group)) GroupInfo.Groups.Add(m_Group); if (m_Current * m_MaxMembers < m_Group.Members.Count) m_Current++; m_Viewer.SendGump(new GroupGump(m_Viewer, m_Group, m_Current)); return; } } } else { GroupInfo.RemoveFromGroup(m_Group.Members[info.ButtonID - (int)GroupButton.Remove], m_Group.Leader); m_Viewer.SendGump(new GroupGump(m_Viewer, m_Group, m_Current)); return; } base.OnResponse(sender, info); }
public override void OnResponse(Network.NetState sender, RelayInfo info) { switch (info.ButtonID) { case (int)LeaderButton.Accept: { GroupInfo.TryGiveGroup(m_CurrentLeader, m_Viewer); return; } case (int)LeaderButton.Refuse: { m_CurrentLeader.SendMessage(m_CurrentLeader.Name + " has refused to lead " + m_CurrentLeader.Group.Name + "."); m_CurrentLeader.SendGump(new GroupGump(m_CurrentLeader, m_CurrentLeader.Group)); return; } default: goto case (int)LeaderButton.Refuse; } base.OnResponse(sender, info); }