{"action":"created","comment":{"url":"https://api.github.com/repos/HippoBaro/R-Type/pulls/comments/89689692","pull_request_review_id":10230237,"id":89689692,"diff_hunk":"@@ -0,0 +1,245 @@\n+//\n+// Created by barre_k on 20/11/16.\n+//\n+\n+#ifndef R_TYPE_RTYPESOCKET_HPP\n+#define R_TYPE_RTYPESOCKET_HPP\n+\n+#include <sys/types.h>\n+#include <sys/socket.h>\n+#include <netinet/in.h>\n+#include <arpa/inet.h>\n+#include <unistd.h> /* close */\n+#include <netdb.h> /* gethostbyname */\n+#include <stdio.h>\n+#include <stdlib.h>\n+#include <errno.h>\n+#include <string.h>\n+\n+#define INVALID_SOCKET -1\n+#define SOCKET_ERROR -1\n+#define closesocket(s) close(s)\n+typedef int SOCKET;\n+typedef struct sockaddr_in SOCKADDR_IN;\n+typedef struct sockaddr SOCKADDR;\n+typedef struct in_addr IN_ADDR;\n+\n+#define PORT 1977\n+#define MAX_CLIENTS 10\n+#define BUF_SIZE 1500\n+\n+#include <stdlib.h>\n+#include \"IRTypeSocket.hpp\"\n+\n+typedef struct {\n+    SOCKADDR_IN sin;\n+}   Client;\n+\n+class RTypeSocket {\n+\n+private:\n+    SOCKET _sock;\n+    SOCKADDR_IN _sin;\n+    fd_set _rdfs;\n+    Client _clients[MAX_CLIENTS];\n+    Client *_actual_client;\n+    char _buffer[BUF_SIZE];\n+    int _actual;\n+    int _max;\n+\n+public:\n+    RTypeSocket()\n+    {\n+        _sin = {0};\n+        _actual = 0;\n+    }\n+\n+    virtual void InitConnection() {\n+        _sock = socket(AF_INET, SOCK_DGRAM, 0);\n+        if (_sock == INVALID_SOCKET) {\n+            std::cerr << \"socket()\" << std::endl;\n+            throw errno;\n+        }\n+\n+        _sin.sin_addr.s_addr = htonl(INADDR_ANY);\n+        _sin.sin_port = htons(PORT);\n+        _sin.sin_family = AF_INET;\n+\n+        if (bind(_sock, (SOCKADDR *) &_sin, sizeof _sin) == SOCKET_ERROR) {\n+            std::cerr << \"bind()\" << std::endl;\n+            throw errno;\n+        }\n+        _max = _sock;\n+    }\n+\n+\n+    virtual void InitConnection(const std::string address) {\n+        _sock = socket(AF_INET, SOCK_DGRAM, 0);\n+        struct hostent *hostinfo;\n+\n+        if (_sock == INVALID_SOCKET) {\n+            std::cerr << \"socket()\" << std::endl;\n+            throw errno;\n+        }\n+\n+        hostinfo = gethostbyname(address.c_str());\n+        if (hostinfo == NULL) {\n+            std::cerr << address << std::endl;\n+            throw errno;\n+        }\n+\n+        _sin.sin_addr = *(IN_ADDR *) hostinfo->h_addr;\n+        _sin.sin_port = htons(PORT);\n+        _sin.sin_family = AF_INET;\n+    }\n+\n+\n+    virtual bool CheckIfClientExists(SOCKADDR_IN *csin) {\n+        int i = 0;\n+        for (i = 0; i < _actual; i++) {\n+            if (_clients[i].sin.sin_addr.s_addr == csin->sin_addr.s_addr\n+                && _clients[i].sin.sin_port == csin->sin_port) {\n+                return true;\n+            }\n+        }\n+\n+        return false;\n+    }\n+\n+    virtual Client *GetClient(SOCKADDR_IN *csin) {\n+        for (int i = 0; i < _actual; i++) {\n+            if (_clients[i].sin.sin_addr.s_addr == csin->sin_addr.s_addr\n+                && _clients[i].sin.sin_port == csin->sin_port) {\n+                return &_clients[i];\n+            }\n+        }\n+        return NULL;\n+    }\n+\n+    virtual void RemoveClient(int to_remove) {\n+        memmove(_clients + to_remove, _clients + to_remove + 1, (_actual - to_remove) * sizeof(Client));\n+        _actual--;\n+    }\n+\n+    virtual void WriteClient(SOCKADDR_IN *sin, const char *buffer) {\n+        if (sendto(_sock, buffer, strlen(buffer), 0, (SOCKADDR *) sin, sizeof *sin) < 0) {\n+            std::cerr << \"send()\" << std::endl;\n+            throw errno;\n+        }\n+    }\n+\n+    virtual void WriteServer(const char* message) {\n+        if (sendto(_sock, message, BUF_SIZE - 1, 0, (SOCKADDR *) &_sin, sizeof *&_sin) < 0) {\n+            std::cerr << \"can't send message\" << std::endl;\n+            throw errno;\n+        }\n+    }\n+\n+\n+    virtual void SendMessageToAllClients(const char *message)\n+    {\n+        for (int i = 0; i < _actual; i++)\n+        {\n+//            if (_actual_client != &_clients[i])\n+//            {\n+//            }\n+            WriteClient(&_clients[i].sin, message);\n+        }\n+    }\n+\n+    virtual void EndConnection() {\n+        closesocket(_sock);\n+    }\n+\n+    virtual ssize_t ReadClient(SOCKADDR_IN *sin)\n+    {\n+        ssize_t n = 0;\n+        socklen_t sinsize = sizeof *sin;\n+\n+        if ((n = recvfrom(_sock, _buffer, BUF_SIZE - 1, 0, (SOCKADDR *) sin, &sinsize)) < 0) {\n+            std::cerr << \"Probleme de reception\" << std::endl;\n+            throw (errno);\n+        }\n+        _buffer[n] = 0;\n+        return n;\n+    }\n+\n+    int ReadServer() {\n+        int n = 0;\n+        socklen_t sinsize = sizeof *(&_sin);\n+\n+        if((n = recvfrom(_sock, _buffer, BUF_SIZE - 1, 0, (SOCKADDR *) &_sin, &sinsize)) < 0)\n+        {\n+            throw errno;\n+        }\n+\n+        _buffer[n] = 0;\n+        return n;\n+\n+    }\n+\n+\n+    char* ListenClient()\n+    {\n+        FD_ZERO(&_rdfs);\n+        FD_SET(STDIN_FILENO, &_rdfs);\n+        FD_SET(_sock, &_rdfs);\n+        if (select(_max + 1, &_rdfs, NULL, NULL, NULL) == -1) {\n+            std::cerr << \"select()\" << std::endl;\n+            throw (errno);\n+        }\n+        if (FD_ISSET(STDIN_FILENO, &_rdfs))\n+        {\n+            EndConnection();\n+            std::cerr << \"key press is not compatiblex\" << std::endl;","path":"Shared/src/RTypeSocket.hpp","position":194,"original_position":194,"commit_id":"75eb9599ddcbb62ef2d567e2f0b52c32617db90d","original_commit_id":"75eb9599ddcbb62ef2d567e2f0b52c32617db90d","user":{"login":"aguadoenzo","id":11411723,"avatar_url":"https://avatars.githubusercontent.com/u/11411723?v=3","gravatar_id":"","url":"https://api.github.com/users/aguadoenzo","html_url":"https://github.com/aguadoenzo","followers_url":"https://api.github.com/users/aguadoenzo/followers","following_url":"https://api.github.com/users/aguadoenzo/following{/other_user}","gists_url":"https://api.github.com/users/aguadoenzo/gists{/gist_id}","starred_url":"https://api.github.com/users/aguadoenzo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aguadoenzo/subscriptions","organizations_url":"https://api.github.com/users/aguadoenzo/orgs","repos_url":"https://api.github.com/users/aguadoenzo/repos","events_url":"https://api.github.com/users/aguadoenzo/events{/privacy}","received_events_url":"https://api.github.com/users/aguadoenzo/received_events","type":"User","site_admin":false},"body":"Probablement une faute ici","created_at":"2016-11-27T13:01:30Z","updated_at":"2016-11-27T13:05:13Z","html_url":"https://github.com/HippoBaro/R-Type/pull/41#discussion_r89689692","pull_request_url":"https://api.github.com/repos/HippoBaro/R-Type/pulls/41","_links":{"self":{"href":"https://api.github.com/repos/HippoBaro/R-Type/pulls/comments/89689692"},"html":{"href":"https://github.com/HippoBaro/R-Type/pull/41#discussion_r89689692"},"pull_request":{"href":"https://api.github.com/repos/HippoBaro/R-Type/pulls/41"}}},"pull_request":{"url":"https://api.github.com/repos/HippoBaro/R-Type/pulls/41","id":95397370,"html_url":"https://github.com/HippoBaro/R-Type/pull/41","diff_url":"https://github.com/HippoBaro/R-Type/pull/41.diff","patch_url":"https://github.com/HippoBaro/R-Type/pull/41.patch","issue_url":"https://api.github.com/repos/HippoBaro/R-Type/issues/41","number":41,"state":"open","locked":false,"title":"Kb socket linux #6","user":{"login":"glacecise","id":9470512,"avatar_url":"https://avatars.githubusercontent.com/u/9470512?v=3","gravatar_id":"","url":"https://api.github.com/users/glacecise","html_url":"https://github.com/glacecise","followers_url":"https://api.github.com/users/glacecise/followers","following_url":"https://api.github.com/users/glacecise/following{/other_user}","gists_url":"https://api.github.com/users/glacecise/gists{/gist_id}","starred_url":"https://api.github.com/users/glacecise/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/glacecise/subscriptions","organizations_url":"https://api.github.com/users/glacecise/orgs","repos_url":"https://api.github.com/users/glacecise/repos","events_url":"https://api.github.com/users/glacecise/events{/privacy}","received_events_url":"https://api.github.com/users/glacecise/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-11-27T09:32:45Z","updated_at":"2016-11-27T13:05:13Z","closed_at":null,"merged_at":null,"merge_commit_sha":null,"assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/HippoBaro/R-Type/pulls/41/commits","review_comments_url":"https://api.github.com/repos/HippoBaro/R-Type/pulls/41/comments","review_comment_url":"https://api.github.com/repos/HippoBaro/R-Type/pulls/comments{/number}","comments_url":"https://api.github.com/repos/HippoBaro/R-Type/issues/41/comments","statuses_url":"https://api.github.com/repos/HippoBaro/R-Type/statuses/75eb9599ddcbb62ef2d567e2f0b52c32617db90d","head":{"label":"HippoBaro:kb_socket_linux_#6","ref":"kb_socket_linux_#6","sha":"75eb9599ddcbb62ef2d567e2f0b52c32617db90d","user":{"login":"HippoBaro","id":6069928,"avatar_url":"https://avatars.githubusercontent.com/u/6069928?v=3","gravatar_id":"","url":"https://api.github.com/users/HippoBaro","html_url":"https://github.com/HippoBaro","followers_url":"https://api.github.com/users/HippoBaro/followers","following_url":"https://api.github.com/users/HippoBaro/following{/other_user}","gists_url":"https://api.github.com/users/HippoBaro/gists{/gist_id}","starred_url":"https://api.github.com/users/HippoBaro/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/HippoBaro/subscriptions","organizations_url":"https://api.github.com/users/HippoBaro/orgs","repos_url":"https://api.github.com/users/HippoBaro/repos","events_url":"https://api.github.com/users/HippoBaro/events{/privacy}","received_events_url":"https://api.github.com/users/HippoBaro/received_events","type":"User","site_admin":false},"repo":{"id":74242392,"name":"R-Type","full_name":"HippoBaro/R-Type","owner":{"login":"HippoBaro","id":6069928,"avatar_url":"https://avatars.githubusercontent.com/u/6069928?v=3","gravatar_id":"","url":"https://api.github.com/users/HippoBaro","html_url":"https://github.com/HippoBaro","followers_url":"https://api.github.com/users/HippoBaro/followers","following_url":"https://api.github.com/users/HippoBaro/following{/other_user}","gists_url":"https://api.github.com/users/HippoBaro/gists{/gist_id}","starred_url":"https://api.github.com/users/HippoBaro/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/HippoBaro/subscriptions","organizations_url":"https://api.github.com/users/HippoBaro/orgs","repos_url":"https://api.github.com/users/HippoBaro/repos","events_url":"https://api.github.com/users/HippoBaro/events{/privacy}","received_events_url":"https://api.github.com/users/HippoBaro/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/HippoBaro/R-Type","description":"Epitech project","fork":false,"url":"https://api.github.com/repos/HippoBaro/R-Type","forks_url":"https://api.github.com/repos/HippoBaro/R-Type/forks","keys_url":"https://api.github.com/repos/HippoBaro/R-Type/keys{/key_id}","collaborators_url":"https://api.github.com/repos/HippoBaro/R-Type/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/HippoBaro/R-Type/teams","hooks_url":"https://api.github.com/repos/HippoBaro/R-Type/hooks","issue_events_url":"https://api.github.com/repos/HippoBaro/R-Type/issues/events{/number}","events_url":"https://api.github.com/repos/HippoBaro/R-Type/events","assignees_url":"https://api.github.com/repos/HippoBaro/R-Type/assignees{/user}","branches_url":"https://api.github.com/repos/HippoBaro/R-Type/branches{/branch}","tags_url":"https://api.github.com/repos/HippoBaro/R-Type/tags","blobs_url":"https://api.github.com/repos/HippoBaro/R-Type/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/HippoBaro/R-Type/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/HippoBaro/R-Type/git/refs{/sha}","trees_url":"https://api.github.com/repos/HippoBaro/R-Type/git/trees{/sha}","statuses_url":"https://api.github.com/repos/HippoBaro/R-Type/statuses/{sha}","languages_url":"https://api.github.com/repos/HippoBaro/R-Type/languages","stargazers_url":"https://api.github.com/repos/HippoBaro/R-Type/stargazers","contributors_url":"https://api.github.com/repos/HippoBaro/R-Type/contributors","subscribers_url":"https://api.github.com/repos/HippoBaro/R-Type/subscribers","subscription_url":"https://api.github.com/repos/HippoBaro/R-Type/subscription","commits_url":"https://api.github.com/repos/HippoBaro/R-Type/commits{/sha}","git_commits_url":"https://api.github.com/repos/HippoBaro/R-Type/git/commits{/sha}","comments_url":"https://api.github.com/repos/HippoBaro/R-Type/comments{/number}","issue_comment_url":"https://api.github.com/repos/HippoBaro/R-Type/issues/comments{/number}","contents_url":"https://api.github.com/repos/HippoBaro/R-Type/contents/{+path}","compare_url":"https://api.github.com/repos/HippoBaro/R-Type/compare/{base}...{head}","merges_url":"https://api.github.com/repos/HippoBaro/R-Type/merges","archive_url":"https://api.github.com/repos/HippoBaro/R-Type/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/HippoBaro/R-Type/downloads","issues_url":"https://api.github.com/repos/HippoBaro/R-Type/issues{/number}","pulls_url":"https://api.github.com/repos/HippoBaro/R-Type/pulls{/number}","milestones_url":"https://api.github.com/repos/HippoBaro/R-Type/milestones{/number}","notifications_url":"https://api.github.com/repos/HippoBaro/R-Type/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/HippoBaro/R-Type/labels{/name}","releases_url":"https://api.github.com/repos/HippoBaro/R-Type/releases{/id}","deployments_url":"https://api.github.com/repos/HippoBaro/R-Type/deployments","created_at":"2016-11-19T23:44:22Z","updated_at":"2016-11-26T23:58:41Z","pushed_at":"2016-11-27T09:32:45Z","git_url":"git://github.com/HippoBaro/R-Type.git","ssh_url":"git@github.com:HippoBaro/R-Type.git","clone_url":"https://github.com/HippoBaro/R-Type.git","svn_url":"https://github.com/HippoBaro/R-Type","homepage":null,"size":22518,"stargazers_count":1,"watchers_count":1,"language":"C++","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":14,"forks":1,"open_issues":14,"watchers":1,"default_branch":"development"}},"base":{"label":"HippoBaro:development","ref":"development","sha":"3b722db60c6c36a59284baa708e344d69c536646","user":{"login":"HippoBaro","id":6069928,"avatar_url":"https://avatars.githubusercontent.com/u/6069928?v=3","gravatar_id":"","url":"https://api.github.com/users/HippoBaro","html_url":"https://github.com/HippoBaro","followers_url":"https://api.github.com/users/HippoBaro/followers","following_url":"https://api.github.com/users/HippoBaro/following{/other_user}","gists_url":"https://api.github.com/users/HippoBaro/gists{/gist_id}","starred_url":"https://api.github.com/users/HippoBaro/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/HippoBaro/subscriptions","organizations_url":"https://api.github.com/users/HippoBaro/orgs","repos_url":"https://api.github.com/users/HippoBaro/repos","events_url":"https://api.github.com/users/HippoBaro/events{/privacy}","received_events_url":"https://api.github.com/users/HippoBaro/received_events","type":"User","site_admin":false},"repo":{"id":74242392,"name":"R-Type","full_name":"HippoBaro/R-Type","owner":{"login":"HippoBaro","id":6069928,"avatar_url":"https://avatars.githubusercontent.com/u/6069928?v=3","gravatar_id":"","url":"https://api.github.com/users/HippoBaro","html_url":"https://github.com/HippoBaro","followers_url":"https://api.github.com/users/HippoBaro/followers","following_url":"https://api.github.com/users/HippoBaro/following{/other_user}","gists_url":"https://api.github.com/users/HippoBaro/gists{/gist_id}","starred_url":"https://api.github.com/users/HippoBaro/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/HippoBaro/subscriptions","organizations_url":"https://api.github.com/users/HippoBaro/orgs","repos_url":"https://api.github.com/users/HippoBaro/repos","events_url":"https://api.github.com/users/HippoBaro/events{/privacy}","received_events_url":"https://api.github.com/users/HippoBaro/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/HippoBaro/R-Type","description":"Epitech project","fork":false,"url":"https://api.github.com/repos/HippoBaro/R-Type","forks_url":"https://api.github.com/repos/HippoBaro/R-Type/forks","keys_url":"https://api.github.com/repos/HippoBaro/R-Type/keys{/key_id}","collaborators_url":"https://api.github.com/repos/HippoBaro/R-Type/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/HippoBaro/R-Type/teams","hooks_url":"https://api.github.com/repos/HippoBaro/R-Type/hooks","issue_events_url":"https://api.github.com/repos/HippoBaro/R-Type/issues/events{/number}","events_url":"https://api.github.com/repos/HippoBaro/R-Type/events","assignees_url":"https://api.github.com/repos/HippoBaro/R-Type/assignees{/user}","branches_url":"https://api.github.com/repos/HippoBaro/R-Type/branches{/branch}","tags_url":"https://api.github.com/repos/HippoBaro/R-Type/tags","blobs_url":"https://api.github.com/repos/HippoBaro/R-Type/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/HippoBaro/R-Type/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/HippoBaro/R-Type/git/refs{/sha}","trees_url":"https://api.github.com/repos/HippoBaro/R-Type/git/trees{/sha}","statuses_url":"https://api.github.com/repos/HippoBaro/R-Type/statuses/{sha}","languages_url":"https://api.github.com/repos/HippoBaro/R-Type/languages","stargazers_url":"https://api.github.com/repos/HippoBaro/R-Type/stargazers","contributors_url":"https://api.github.com/repos/HippoBaro/R-Type/contributors","subscribers_url":"https://api.github.com/repos/HippoBaro/R-Type/subscribers","subscription_url":"https://api.github.com/repos/HippoBaro/R-Type/subscription","commits_url":"https://api.github.com/repos/HippoBaro/R-Type/commits{/sha}","git_commits_url":"https://api.github.com/repos/HippoBaro/R-Type/git/commits{/sha}","comments_url":"https://api.github.com/repos/HippoBaro/R-Type/comments{/number}","issue_comment_url":"https://api.github.com/repos/HippoBaro/R-Type/issues/comments{/number}","contents_url":"https://api.github.com/repos/HippoBaro/R-Type/contents/{+path}","compare_url":"https://api.github.com/repos/HippoBaro/R-Type/compare/{base}...{head}","merges_url":"https://api.github.com/repos/HippoBaro/R-Type/merges","archive_url":"https://api.github.com/repos/HippoBaro/R-Type/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/HippoBaro/R-Type/downloads","issues_url":"https://api.github.com/repos/HippoBaro/R-Type/issues{/number}","pulls_url":"https://api.github.com/repos/HippoBaro/R-Type/pulls{/number}","milestones_url":"https://api.github.com/repos/HippoBaro/R-Type/milestones{/number}","notifications_url":"https://api.github.com/repos/HippoBaro/R-Type/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/HippoBaro/R-Type/labels{/name}","releases_url":"https://api.github.com/repos/HippoBaro/R-Type/releases{/id}","deployments_url":"https://api.github.com/repos/HippoBaro/R-Type/deployments","created_at":"2016-11-19T23:44:22Z","updated_at":"2016-11-26T23:58:41Z","pushed_at":"2016-11-27T09:32:45Z","git_url":"git://github.com/HippoBaro/R-Type.git","ssh_url":"git@github.com:HippoBaro/R-Type.git","clone_url":"https://github.com/HippoBaro/R-Type.git","svn_url":"https://github.com/HippoBaro/R-Type","homepage":null,"size":22518,"stargazers_count":1,"watchers_count":1,"language":"C++","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":14,"forks":1,"open_issues":14,"watchers":1,"default_branch":"development"}},"_links":{"self":{"href":"https://api.github.com/repos/HippoBaro/R-Type/pulls/41"},"html":{"href":"https://github.com/HippoBaro/R-Type/pull/41"},"issue":{"href":"https://api.github.com/repos/HippoBaro/R-Type/issues/41"},"comments":{"href":"https://api.github.com/repos/HippoBaro/R-Type/issues/41/comments"},"review_comments":{"href":"https://api.github.com/repos/HippoBaro/R-Type/pulls/41/comments"},"review_comment":{"href":"https://api.github.com/repos/HippoBaro/R-Type/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/HippoBaro/R-Type/pulls/41/commits"},"statuses":{"href":"https://api.github.com/repos/HippoBaro/R-Type/statuses/75eb9599ddcbb62ef2d567e2f0b52c32617db90d"}}}}
{"actor":{"display_login":"aguadoenzo"}}