summaryrefslogtreecommitdiffstats
path: root/friendfinder/sender.c
diff options
context:
space:
mode:
Diffstat (limited to 'friendfinder/sender.c')
-rw-r--r--friendfinder/sender.c57
1 files changed, 43 insertions, 14 deletions
diff --git a/friendfinder/sender.c b/friendfinder/sender.c
index edb5b61..cc0ef0b 100644
--- a/friendfinder/sender.c
+++ b/friendfinder/sender.c
@@ -11,6 +11,9 @@
static irc_session_t *session;
irc_callbacks_t callbacks;
+int exit_ = 0;
+int lat_first_set = 0;
+
int msg_count = 0;
int ack_count = 0;
int resend = 0;
@@ -28,6 +31,11 @@ void sender_set_ip(char *_sender_server_ip)
sender_server_ip = _sender_server_ip;
}
+void set_sender_exit()
+{
+ exit_ = 1;
+}
+
int init_connection_sender(char* server_ip, char* user)
{
printf("SENDER: initialising connection...\n");
@@ -57,9 +65,19 @@ void disconnect_sender()
void set_sender_position(double lat, double lon)
{
- own_lat = lat;
- own_lon = lon;
- printf("%f || %f \n", lat, lon);
+ if (lat_first_set = 0)
+ {
+ own_lat = lat;
+ own_lon = lon;
+
+ lat_first_set = 1;
+ }
+
+ if (((own_lat - lat) > 0.000130 || (own_lat - lat) < 0.000130) || ((own_lon - lon) > 0.000130 || (own_lon - lon) < 0.000130))
+ {
+ own_lat = lat;
+ own_lon = lon;
+ }
}
struct sender_data* prepare_position(const unsigned char* lat, const unsigned char* lon)
@@ -102,13 +120,11 @@ struct sender_data* prepare_position(const unsigned char* lat, const unsigned ch
pos->lon_first[5] = 'c';
pos->lon_first[6] = '\0';
- pos->lon_second[4] = 'd';
- pos->lon_second[5] = '\0';
-
-
- printf(" %s %s \n", pos->lat_first, pos->lat_second);
- printf(" %s %s \n", pos->lon_first, pos->lon_second);
+ pos->lon_second[3] = 'd';
+ pos->lon_second[4] = '\0';
+// printf(" %s %s \n", pos->lat_first, pos->lat_second);
+// printf(" %s %s \n", pos->lon_first, pos->lon_second);
return pos;
}
@@ -133,8 +149,14 @@ void send_position(irc_session_t * session, const char * event, const char * ori
irc_cmd_msg(session, "#test", "connected");
first_send = 1;
+
+ free(keyd->key);
+ free(keyd);
}
+ if (exit_ == 1)
+ disconnect_sender();
+
const unsigned char *lat_char = (char*) malloc(sizeof(char) * 9);
sprintf(lat_char, "%f", own_lat);
@@ -152,15 +174,13 @@ void send_position(irc_session_t * session, const char * event, const char * ori
BF_ecb_encrypt(pos->lon_second, crypted_lon_second, &key, BF_ENCRYPT);
irc_cmd_msg(session, "#test", crypted_lat_first);
- sleep(1);
+
irc_cmd_msg(session, "#test", crypted_lat_second);
- sleep(1);
irc_cmd_msg(session, "#test", crypted_lon_first);
- sleep(1);
- irc_cmd_msg(session, "#test", crypted_lon_second);
- sleep(1);
+ irc_cmd_msg(session, "#test", crypted_lon_second);
+
//increase counter variable, which counts number of send positions!
msg_count = msg_count + 2;
@@ -179,6 +199,12 @@ void send_position(irc_session_t * session, const char * event, const char * ori
free(crypted_lon_first);
free(crypted_lon_second);
+
+ free(pos->lon_first);
+ free(pos->lon_second);
+ free(pos->lat_first);
+ free(pos->lat_second);
+ free(pos);
}
void get_aknowledge(irc_session_t * session, const char * event, const char * origin, const char ** params, unsigned int count)
@@ -196,6 +222,9 @@ void get_aknowledge(irc_session_t * session, const char * event, const char * or
if (ack_count == 2 && msg_count == 0)
{
resend = 1;
+
+ sleep(5);
+
send_position(session, event, origin, params, count);
}
}