public override string HandleCommand(DaemonCommandBase command) { if (command is USERTABLECommand) { int count = 0; string [] respones = new string[1]; respones[0] = ""; Backend.DaemonBackEnd.Instance.UpdateRoutingTable(); foreach (Entities.RoutingTableEntry e in Backend.DaemonBackEnd.Instance.RoutingTable) { if (e.Node.NodeID != Backend.DaemonBackEnd.Instance.LocalNode.NodeID) { count += e.Node.Users.Count; foreach (Entities.User u in e.Node.Users) { if (e.NextHop == null) { respones[0] += u.Nickname + " " + e.Node.NodeID.ToString() + " " + e.Distance.ToString() + "\n"; } else { respones[0] += u.Nickname + " " + e.NextHop.NodeID.ToString() + " " + e.Distance.ToString() + "\n"; } } } } respones[0] = count.ToString() + "\n" + respones[0]; return(Utilities.Responses.GetResponse(Utilities.ResponseCodes.UserTable_OK, respones)); } else { return("ERROR"); } }
/// <summary> /// Waits for IRC server connections. /// </summary> private void WaitForIRCServerConnection() { ircServer = new IRCServer(daemonTCPSocket); while (true) { try { DaemonCommandBase daemand = ircServer.ReceiveCommand(); string Response = daemand.ExecuteCommand(); ircServer.SendResponse(Response); } catch { continue; } } }
public override string HandleCommand(DaemonCommandBase command) { string[] respones = new string[2]; if (command is NEXTHOPCommand) { NEXTHOPCommand nextHopCommand = (NEXTHOPCommand)command; if (nextHopCommand.NickName == null) { return("ERROR"); } Entities.User U = new Entities.User(); U.Nickname = nextHopCommand.NickName; Backend.DaemonBackEnd.Instance.UpdateRoutingTable(); foreach (Entities.RoutingTableEntry e in Backend.DaemonBackEnd.Instance.RoutingTable) { if (e.Node.Users.Contains(U)) { if (e.NextHop == null) { if (e.Node.NodeID == Backend.DaemonBackEnd.Instance.LocalNode.NodeID) { return("None"); } else { respones[0] = e.Node.NodeID.ToString(); respones[1] = e.Distance.ToString(); return(Utilities.Responses.GetResponse(Utilities.ResponseCodes.NextHop_OK, respones)); } } if (e.NextHop.NodeID != Backend.DaemonBackEnd.Instance.LocalNode.NodeID) { respones[0] = e.NextHop.NodeID.ToString(); respones[1] = e.Distance.ToString(); return(Utilities.Responses.GetResponse(Utilities.ResponseCodes.NextHop_OK, respones)); } } } return("None"); } else { return("ERROR"); } }
public override string HandleCommand(DaemonCommandBase command) { if (command is ADDUSERCommand) { ADDUSERCommand AddUserCommand = (ADDUSERCommand)command; if (AddUserCommand.NickName == null) { return("Error"); } User n = new User(); n.Nickname = AddUserCommand.NickName; bool found = DaemonBackEnd.Instance.LocalNode.Users.Contains(n); if (found == false) { DaemonBackEnd.Instance.LocalNode.Users.Add(n); } return("ok"); } else { return("Error"); } }
public override string HandleCommand(DaemonCommandBase command) { if (command is REMOVEUSERCommand) { REMOVEUSERCommand RemoveUserCommand = (REMOVEUSERCommand)command; if (RemoveUserCommand.NickName == null) { return("ERROR"); } User n = new User(); n.Nickname = RemoveUserCommand.NickName; bool found = DaemonBackEnd.Instance.LocalNode.Users.Contains(n); if (found) { DaemonBackEnd.Instance.LocalNode.Users.Remove(n); } return("OK"); } else { return("ERROR"); } }
public abstract string HandleCommand(DaemonCommandBase command);
public override string HandleCommand(DaemonCommandBase command) { return(null); if (command is ADDUSERCommand) { // USERCommand userCommand = (USERCommand)command; // if(userCommand.UserName==null||userCommand.HostName==null||userCommand.ServerName==null||userCommand.RealName==null) // { // return Errors.GetErrorResponse(ErrorCode.ERR_NEEDMOREPARAMS,"User"); // } // if (session.User != null) // { // if (session.User.Username != null) // { // return Errors.GetErrorResponse(ErrorCode.ERR_ALREADYREGISTERED, null); // } // } // //foreach (User u in ServerBackend.Instance.Users) // //{ // // if (u.Username == userCommand.UserName) // // { // // return Errors.GetErrorResponse(ErrorCode.ERR_ALREADYREGISTERED, null); // // } // //} // foreach (User user in ServerBackend.Instance.Users) // { // if (user == session.User) // { // if (user.Nickname != null) // { // session.User.Username = userCommand.UserName; // session.User.Hostname = userCommand.HostName; // session.User.Realname = userCommand.RealName; // session.ConnectionState = ConnectionState.Registered; // return "OK"; // } // else // { // session.User.Username = userCommand.UserName; // session.User.Hostname = userCommand.HostName; // session.User.Realname = userCommand.RealName; // session.ConnectionState = ConnectionState.NotRegistered; // return "OK"; // } // } // } // if (session.User == null) // { // session.User = new User(); // session.User.Username = userCommand.UserName; // session.User.Hostname = userCommand.HostName; // session.User.Realname = userCommand.RealName; // session.ConnectionState = ConnectionState.NotRegistered; // ServerBackend.Instance.Users.Add(session.User); // } // return "OK"; //} //else //{ // throw new ArgumentException(); //} } }