| summaryrefslogtreecommitdiff |
diff options
| author | Nathanael Sensfelder <SpamShield0@MultiAgentSystems.org> | 2016-06-08 17:58:56 +0200 |
|---|---|---|
| committer | Nathanael Sensfelder <SpamShield0@MultiAgentSystems.org> | 2016-06-08 17:58:56 +0200 |
| commit | 16265ec44520c3926c11127d0a6a6bac82a53275 (patch) | |
| tree | e54aeed621509655e0e5a5c8a0d1ef3bc50be7f9 /src/core/main.c | |
| parent | d29327bdc629dfa37360465b03ef45d205e7a225 (diff) | |
ZoO now appends anything it learns to a file.
Also, removes the "pointing to [...]" message, which was used for debug
purposes.
Diffstat (limited to 'src/core/main.c')
| -rw-r--r-- | src/core/main.c | 109 |
1 files changed, 95 insertions, 14 deletions
diff --git a/src/core/main.c b/src/core/main.c index 1a8a40f..15df961 100644 --- a/src/core/main.c +++ b/src/core/main.c @@ -9,9 +9,9 @@ #include "../io/error.h" #include "../io/parameters.h" #include "../io/data_input.h" +#include "../io/data_output.h" #include "../io/network.h" - #include "knowledge.h" #include "state_types.h" @@ -152,15 +152,52 @@ static int should_reply static void handle_user_join ( - struct ZoO_state s [const static 1] + struct ZoO_state s [const static 1], + struct ZoO_strings string [const restrict static 1], + ssize_t const msg_offset, + ssize_t const msg_size ) { ZoO_char * line; + ZoO_index loc; + + if (s->param.reply_rate < (rand() % 100)) + { + return; + } if ( - (s->param.reply_rate >= (rand() % 100)) - && + ZoO_strings_parse + ( + string, + (size_t) msg_size, + (s->network.in + msg_offset), + ZoO_knowledge_punctuation_chars_count, + ZoO_knowledge_punctuation_chars + ) < 0 + ) + { + ZoO_S_DEBUG(ZoO_DEBUG_PROGRAM_FLOW, "Could not dissect join username."); + + return; + } + + if + ( + ( + ZoO_knowledge_find + ( + &(s->knowledge), + string->words[0], + &loc + ) < 0 + ) + || (s->knowledge.words[loc].backward_links_count <= 3) + || (s->knowledge.words[loc].forward_links_count <= 3) + ) + { + if ( ZoO_knowledge_extend ( @@ -170,20 +207,47 @@ static void handle_user_join &line ) == 0 ) - ) - { - if (line[0] == ' ') { - strcpy((s->network.out), (line + 1)); + if (line[0] == ' ') + { + strcpy((s->network.out), (line + 1)); + } + else + { + strcpy((s->network.out), line); + } + + free((void *) line); + + ZoO_network_send(&(s->network)); } - else + } + else + { + if + ( + ZoO_knowledge_extend + ( + &(s->knowledge), + string, + 0, + &line + ) == 0 + ) { - strcpy((s->network.out), line); - } + if (line[0] == ' ') + { + strcpy((s->network.out), (line + 1)); + } + else + { + strcpy((s->network.out), line); + } - free((void *) line); + free((void *) line); - ZoO_network_send(&(s->network)); + ZoO_network_send(&(s->network)); + } } } @@ -192,6 +256,9 @@ static void handle_message struct ZoO_state s [const static 1], struct ZoO_strings string [const restrict static 1], ssize_t const msg_offset, + /* FIXME: somehow we end up using (msg_size + 1), meaning there's a mixup + * between size and length. + */ ssize_t const msg_size ) { @@ -222,6 +289,20 @@ static void handle_message reply = should_reply(&(s->param), string, &learn); + if (learn) + { + /* + * It would be best to do that after replying, but by then we no longer + * have the string in 's->network.in'. + */ + (void) ZoO_data_output_write_line + ( + s->param.new_data_filename, + (s->network.in + msg_offset), + (size_t) (msg_size + 1) + ); + } + if ( reply @@ -290,7 +371,7 @@ static int main_loop (struct ZoO_state s [const static 1]) switch (msg_type) { case ZoO_JOIN: - handle_user_join(s); + handle_user_join(s, &string, msg_offset, msg_size); break; case ZoO_PRIVMSG: |


