Skip to content

Commit

Permalink
Various changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Justin Crawford authored and Justin Crawford committed Sep 18, 2011
1 parent a706a6b commit 01b04ad
Show file tree
Hide file tree
Showing 12 changed files with 26 additions and 215 deletions.
2 changes: 2 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ Added User::IsOwner boolean
Added new logging function
Added a new compile system (GNU make) so navn can compile files correctly
Rewrote the INIReader into C++ so now it is more effecent at its job
Removed Make_two_digits as i (justasic) have no clue what it does and its not used anywhere
Deprecated irc_string::isolate() as its been replaced by the global function isolate() which does the same thing

Navn 2.0.0
==========
Expand Down
3 changes: 2 additions & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ all:
@echo "Navn Version @VERSION@-with-netflix-and-chicken"
@echo " "
@$(PERL) $(CXX) $(CFLAGS) -c main.cpp
@$(PERL) $(CXX) $(CFLAGS) -c process.cpp
@$(PERL) $(CXX) $(CFLAGS) -c misc.cpp
@$(PERL) $(CXX) $(CFLAGS) -c module.cpp
@$(PERL) $(CXX) $(CFLAGS) -c Socket.cpp
Expand All @@ -20,7 +21,7 @@ all:
@$(PERL) $(CXX) $(CFLAGS) -c timers.cpp
@$(PERL) $(CXX) $(CFLAGS) -c user.cpp
@$(PERL) $(CXX) $(CFLAGS) -c INIReader.cpp
@$(PERL) $(CXX) $(CFLAGS) -o $(EXECUTABLE) main.o misc.o module.o Socket.o Sepstream.o privmsg.o command.o channel.o thread.o timers.o user.o INIReader.o $(LIBS)
@$(PERL) $(CXX) $(CFLAGS) -o $(EXECUTABLE) main.o misc.o module.o Socket.o Sepstream.o privmsg.o command.o channel.o thread.o timers.o user.o INIReader.o process.o $(LIBS)
@$(PERL) $(CXX) $(CFLAGS) -c testmod.cpp
@$(PERL) $(CXX) $(MODFLAGS)testmod.so -o testmod.so testmod.o
@echo " "
Expand Down
3 changes: 2 additions & 1 deletion Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,7 @@ all:
@echo "Navn Version @VERSION@-with-netflix-and-chicken"
@echo " "
@$(PERL) $(CXX) $(CFLAGS) -c main.cpp
@$(PERL) $(CXX) $(CFLAGS) -c process.cpp
@$(PERL) $(CXX) $(CFLAGS) -c misc.cpp
@$(PERL) $(CXX) $(CFLAGS) -c module.cpp
@$(PERL) $(CXX) $(CFLAGS) -c Socket.cpp
Expand All @@ -491,7 +492,7 @@ all:
@$(PERL) $(CXX) $(CFLAGS) -c timers.cpp
@$(PERL) $(CXX) $(CFLAGS) -c user.cpp
@$(PERL) $(CXX) $(CFLAGS) -c INIReader.cpp
@$(PERL) $(CXX) $(CFLAGS) -o $(EXECUTABLE) main.o misc.o module.o Socket.o Sepstream.o privmsg.o command.o channel.o thread.o timers.o user.o INIReader.o $(LIBS)
@$(PERL) $(CXX) $(CFLAGS) -o $(EXECUTABLE) main.o misc.o module.o Socket.o Sepstream.o privmsg.o command.o channel.o thread.o timers.o user.o INIReader.o process.o $(LIBS)
@$(PERL) $(CXX) $(CFLAGS) -c testmod.cpp
@$(PERL) $(CXX) $(MODFLAGS)testmod.so -o testmod.so testmod.o
@echo " "
Expand Down
3 changes: 3 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Did you know that the command !poke is the oldest known command in Da_Goat? (Da_Goat came long before Navn as an xchat python script)
Did you know that the class irc_string is the oldest class in Navn?
Did you know that !time is so old that it was made before the ping/pong function?
41 changes: 5 additions & 36 deletions flux_net_irc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ DEPRECATED(Flux::string params(unsigned b, unsigned e)){
* \param end The character saying where the cut should end.
* \param msg The Flux::string you are wanting to isolate from.
*/
static Flux::string isolate(char begin, char end, Flux::string msg){
DEPRECATED(static Flux::string cisolate(char begin, char end, Flux::string msg)){
Flux::string to_find;
size_t pos = msg.find(begin);
pos += 1;
Expand Down Expand Up @@ -193,11 +193,11 @@ class IsoHost:Flux::string{
* \fn IsoHost(Flux::string fullhost)
* \param fullhost A Flux::string containing the full host of an irc message
*/
IsoHost(Flux::string fullhost){
nick = irc_string::isolate(':','!',fullhost);
IsoHost(const Flux::string &fullhost){
nick = isolate(':','!',fullhost);
raw = fullhost;
host = irc_string::isolate('@',' ',fullhost);
user = irc_string::isolate('!','@',fullhost);
host = isolate('@',' ',fullhost);
user = isolate('!','@',fullhost);
}

};
Expand Down Expand Up @@ -296,24 +296,6 @@ Flux::string execute(const char *cmd) {
#endif
return result;
}

/**
* \fn Flux::string make_two_digits(int x)
* \brief Makes single digit int into a double digit Flux::string.
* This was really just for the \a world_clock module but it's handy to have around.
* \param x A single digit integer.
* \return A Flux::string containing integer as a double digit.
*/
Flux::string make_two_digits(int x){
std::stringstream dd_ss;
if (x < 10){
dd_ss << "0" << x;
return dd_ss.str();
}else{
dd_ss << x;
return dd_ss.str();
}
}
/**
*\fn Flux::string os_time()
*\brief Get the operating system's time
Expand Down Expand Up @@ -601,19 +583,6 @@ Flux::string findInXML(const Flux::string &node, const Flux::string &info, const
}
return output;
}
Flux::string xmlparse(const Flux::string &node, const Flux::string &info, const Flux::string &FileString){
printf("xmlparse called\n");
size_t n1 = FileString.find('<');
size_t n2 = FileString.find('>');

if(n1 > FileString.length() || n2 > FileString.length())
return "";

Flux::string data;
data.assign(FileString,n1,n2);
printf("%s\n", data.c_str());
return data;
}
/*******************************************************************/
namespace ThreadHandler
{
Expand Down
4 changes: 2 additions & 2 deletions include/extern.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ extern Flux::string nick, owner_nick, logfile, binary_path, bot_bin, binary_dir;
extern Flux::string strip(const Flux::string &buf);
extern Flux::string getprogdir(const Flux::string&);
extern Flux::string TempFile(const Flux::string&);
extern Flux::string isolate(char begin, char end, const Flux::string &msg);
extern Flux::string make_pass();
extern int randint(int x, int y);
extern bool IsValidChannel(const Flux::string&);
Expand All @@ -52,6 +53,7 @@ extern std::vector<Flux::string> StringVector(const Flux::string&, char);
extern std::vector<module*> moduleList;
extern Flux::insensitive_map<User *> UserNickList;
extern Flux::insensitive_map<Channel*> ChanMap;
extern char **my_av, **my_envp;

/* Typedef's */

Expand All @@ -65,6 +67,4 @@ void process(const Flux::string&);
void ProcessJoin(CommandSource&, const Flux::string&);
void ProcessModules(CommandSource&, std::vector<Flux::string>&);

/* char*'s */
extern char **my_av, **my_envp;
#endif
8 changes: 5 additions & 3 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ int main (int argcx, char** argvx, char *envp[])
about_me _about_me(true);
Da_Goat _Da_Goat(true);
Flux_Services _Flux_Services(false);
encyclopedia _encyclopedia(true);
encyclopedia _encyclopedia(false);
/*
TinyURL _TinyURL(false);
*/
Expand All @@ -122,7 +122,8 @@ int main (int argcx, char** argvx, char *envp[])

/* Process the buffer and modules */
std::queue<Flux::string> queue = sock->GetBuffer();
while(!queue.empty()){
while(!queue.empty())
{
if(queue.empty())
break;
process(queue.front());
Expand All @@ -131,7 +132,8 @@ int main (int argcx, char** argvx, char *envp[])
}
/* Process Timers */
/***********************************/
if(time(NULL) - last_check >= 3){
if(time(NULL) - last_check >= 3)
{
TimerManager::TickTimers(time(NULL));
last_check = time(NULL);
}
Expand Down
166 changes: 2 additions & 164 deletions misc.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* All code is licensed under GNU General Public License GPL v3 (http://www.gnu.org/licenses/gpl.html) */
#include <includes.h>
#include <user.h>
#include "user.h"

//General misc functions
/** \fn Flux::string strip(const Flux::string &buf)
Expand Down Expand Up @@ -90,7 +89,7 @@ bool IsValidChannel(const Flux::string &chan){
* \param end The character saying where the cut should end.
* \param msg The Flux::string you are wanting to isolate from.
*/
Flux::string isolate(char begin, char end, Flux::string msg){
Flux::string isolate(char begin, char end, const Flux::string &msg){
Flux::string to_find;
size_t pos = msg.find(begin);
pos += 1;
Expand Down Expand Up @@ -181,167 +180,6 @@ std::vector<Flux::string> StringVector(const Flux::string &src, char delim){
ret.push_back(token);
return ret;
}
/**
* \fn void ProcessJoin(CommandSource &source, const Flux::string &chan)
* \brief Processes the /who numeric (352), this should only be used in Process() unless its for something special
* \param source CommandSource struct used to find all the information needed to make new users
* \param chan The channel we're processing
*/
void ProcessJoin(CommandSource &source, const Flux::string &chan){
std::vector<Flux::string> &params = source.params;
if(params.size() < 7)
return;
Flux::string channel = params[1];
Flux::string Ident = params[2];
Flux::string Host = params[3];
Flux::string Server = params[4];
Flux::string Nickname = params[5];
Flux::string opstatus = params[6];
Flux::string realname = params[7].erase(0,2);
/*******************************************************/
User *u = finduser(Nickname);
if(!u){
if(!Host.empty() || !Nickname.empty() || !Ident.empty())
u = new User(Nickname, Ident, Host, realname, Server);
}
Channel *c = findchannel(channel);
if(!c){
if(!channel.empty())
c = new Channel(channel);
}
}
/*********************************************************************************/

/**
* \fn void process(const Flux::string &buffer)
* \brief Main Processing function
* \param buffer The raw socket buffer
*/
void process(const Flux::string &buffer){
Flux::string buf = buffer;
buf = buf.replace_all_cs(" ", " ");
if(buf.empty())
return;
Flux::string source;
if(buf[0] == ':'){
size_t space = buf.find_first_of(" ");
if(space == Flux::string::npos)
return;
source = buf.substr(1, space - 1);
buf = buf.substr(space + 1);
if(source.empty() || buf.empty())
return;
}
sepstream bufferseparator(buf, ' ');
Flux::string bufferseparator_token;
Flux::string command = buf;
if(bufferseparator.GetToken(bufferseparator_token))
command = bufferseparator_token;
std::vector<Flux::string> params;

while(bufferseparator.GetToken(bufferseparator_token))
{
if(bufferseparator_token[0] == ':'){
if(!bufferseparator.StreamEnd())
params.push_back(bufferseparator_token.substr(1)+" "+bufferseparator.GetRemaining());
else
params.push_back(bufferseparator_token.substr(1));
break;
}
else
params.push_back(bufferseparator_token);
}
log(LOG_RAWIO, "Received: %s\n", Flux::Sanitize(buffer).c_str());
if(protocoldebug)
{
printf("Source: %s\n", source.empty() ? "No Source" : source.c_str());
printf("%s: %s\n", command.is_number_only() ? "Numeric" : "Command", command.c_str());
if(params.empty())
printf("No Params\n");
else
for(unsigned i =0; i < params.size(); ++i)
printf("Params %i: %s\n", i, Flux::Sanitize(params[i]).c_str());
}
/**************************************/
const Flux::string &receiver = params.size() > 0 ? params[0] : "";
Flux::string message = params.size() > 1? params[1] : "";

if(command == "PRIVMSG")
{
if(!protocoldebug){
if(!receiver.empty() && !params[1].empty())
log(LOG_TERMINAL, "<%s-%s> %s\n", isolate(':','!',source).c_str(), receiver.c_str(), params[1].c_str());
}
}else{
if(!protocoldebug)
log(LOG_DEBUG, "%s\n", Flux::Sanitize(buffer).c_str());
}
/* make local variables instead of global ones */
Flux::string nickname = isolate(':','!',source),
uident = isolate('!','@',source),
uhost = isolate('@',' ',source);

User *u = finduser(nickname);
Channel *c = findchannel(receiver);

if(!u){
if(nickname.empty() || uident.empty() || uhost.empty()){ }else
u = new User(nickname, uident, uhost);
}
if(command == "QUIT"){
if(u)
delete u;
}
if(command == "PART"){
if(IsValidChannel(receiver)){
c = findchannel(receiver);
if(c && u && u->nick == nick)
delete c;
}else{
delete u;
}
}
if(command == "NICK"){
if(u){
if(u->nick == nick){
nick = params[0];
delete u; //we shouldnt be a user in the 1st place (:
}else if(u->nick == owner_nick){
owner_nick = params[0];
}
else{
delete u; //we delete the user because the above if statement makes a new one for the nick change
}
}
}
if(command == "JOIN"){
if(!u){
if(nickname.empty() || uident.empty() || uhost.empty()){ }else
u = new User(nickname, uident, uhost);
}
c = findchannel(receiver);
if(!c){
if(IsValidChannel(receiver))
c = new Channel(receiver);
}
if(u->nick == nick)
c->SendWho();
}
/**************************************/
CommandSource Source;
Source.u = u; //User class
Source.c = c; //Channel class
Source.command = command;
Source.message = message;
Source.params = params;
Source.raw = buffer;
if(command == "352"){
ProcessJoin(Source, c->name);
}
std::vector<Flux::string> params2 = StringVector(message, ' ');
if(source.empty() || message.empty() || params2.empty())
return;
ProcessModules(Source, params2);
}
/* butt-plug?
* http://www.albinoblacksheep.com/flash/plugs */
5 changes: 1 addition & 4 deletions modules/ctcp.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,14 @@ class ctcp:public module
throw CoreException("uname() Error");

source.Reply("\001VERSION Navn-%s %s %s\001",VERSION, uts.sysname, uts.machine);
//log(LOG_NORMAL, "Recieved CTCP VERSION from %s", u->nick.c_str());
}
if(cmd == "\001TIME\001"){ // for CTCP TIME reply
source.Reply("\001TIME "+strip(os_time())+"\001");
//log(LOG_NORMAL, "Recieved CTCP TIME from %s", u->nick.c_str());
source.Reply("\001TIME %s\001", os_time().c_str());
}
if(cmd == "\001SOURCE\001"){
source.Reply("\001SOURCE https://gitorious.org/navn/navn\001");
source.Reply("\001SOURCE http://flux-net.googlecode.com/svn/branches/Navn/\001");
source.Reply("\1SOURCE git://gitorious.org/navn/navn.git\1");
//log(LOG_NORMAL, "Recieved CTCP SOURCE from %s", u->nick.c_str());
}
return MOD_RUN;
}
Expand Down
2 changes: 1 addition & 1 deletion modules/da_goat.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class Da_Goat:public module
}
}
if(cmd.equals_ci("!info")){
c->SendMessage("Our forum is at \037castawaycrew.hyperboards.com\017");
c->SendMessage("Our forum is at \037http://flux-net.net/forum2/\017");
c->SendMessage("Our Website is \002Flux-Net.net\017");
c->SendMessage("Ftp server \002178.63.127.231\002 login anonymous \002-no password-\002, Files in dir \002/ftp/pub\002");
log(LOG_NORMAL, "%s used Da_Goats !info command in %s", u->nick.c_str(), c->name.c_str());
Expand Down
2 changes: 1 addition & 1 deletion modules/navn.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class navn:public module{
source.Reply(ACCESS_DENIED);
}
}
if (cmd.equals_ci("join")){
if(cmd.equals_ci("join")){
Flux::string blah = params.size() == 2 ? params[1] : "";
if(blah.empty()){
source.Reply("Syntax: \2Join \37channel\15");
Expand Down
Loading

0 comments on commit 01b04ad

Please sign in to comment.