Homebrew [Request] Texting Application

  • Thread starter Thread starter Alex Spady
  • Start date Start date
  • Views Views 4,966
  • Replies Replies 52
Okay. What are the big differences in C and C++?

--------------------- MERGED ---------------------------

Just made a GitHub repository. https://github.com/amspady20/3DSText

I had made one previously, though... https://github.com/skewerr/dim :<

And differences between C++ and C... tl;dr: C++ has OOP. That's the best answer I can give you. There are some changes to C's imperative(iterative?) syntax in C++. There are namespaces you can create, unlike in C(it has namespaces, but you can't really create new ones, so the idea of namespace isn't strong), etc.

People use C++ or Objective-C for OOP. Java isn't reliable, speed-wise, as its implementations run on the JVM. Python is interpreted, and its implementations are also not very reliable, speed-wise. Think of C++ as "OOP + speed of C implementations".
 
I'd like to help in any way I can. I know a bit of C but I don't know anything about networking stuff. Is there anyway I could help with something?
 
This is the perfect learning opportunity for you. Instead of offering help, ask for help on how you can develop your own homebrew. It's a fairly simple concept and if you really want to learn I can help you.
Would you be open to helping me too? I could work with you guys
 
On this project, i was thinking i maybe could help you guys, i wouldn't be good at necessarily the layout coding, but the networking and imaging yeah!
I don't know what you mean by layout coding, but I don't think anyone is working on this project
 
If @Tjessx releases the source code for their Pictochat homebrew(and server), you can use that to begin messing around with sockets.

I like the idea, maybe I can be of some help? I don't know C++, but I know C. Still a beginner, but eager to get involved.

There you go:
Code:
#include <3ds.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>

#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <stdio.h>
#include <unistd.h>
#include <malloc.h>
#include <fcntl.h>
#include <errno.h>

#include "connection.h"
#include "color.h"
#include "messages.h"
#include "menu.h"
#include "main.h"

static void *SOC_buffer = NULL;
static int chatls = -1;

#define STACKSIZE (4 * 1024)

int con_init(void) {
    SOC_buffer = memalign(0x1000, 0x100000);
    if(SOC_buffer == NULL)
        return -1;

    Result ret = SOC_Initialize(SOC_buffer, 0x100000);
    if(ret != 0)
    {
        SOC_Shutdown();
        free(SOC_buffer);
        SOC_buffer = NULL;
        return -1;
    }
    return 0;
}

int con_dinit(void) {
    if(chatls >= 0) {
        closesocket(chatls);
        chatls = -1;
    }
   
    Result ret = SOC_Shutdown();
   
    if(ret < 0) {
        return -1;
    }
    return 0;
}
void sock_send(char* message, size_t size) {
    int n = sendto(chatls, message, size, 0, NULL, 0);
    if (n == -1)
    {
       add_message("ERROR writing to socket", 1, white, background_message);
    }
}

void send_handshake() {
    //I used this to send a login message, not gonna share this part sorry
}

static int set_socket_nonblocking(int sock) {
    int flags = fcntl(sock, F_GETFL);

    if(flags == -1) return -1;

    int rc = fcntl(sock, F_SETFL, flags | O_NONBLOCK);

    if(rc != 0) return -1;

    return 0;
}

static int sock_receive(char* message, size_t size) {
    int len;
    len = recv(chatls, message, size, 0);
    
    if (len == -1) {
        if (errno != EAGAIN && errno != EWOULDBLOCK) {
            return -1;
        }
    }
    return len;
}

void get_message() {
    char message[500] = "";
    int n = sock_receive(message, 500);
    if(n > 0) {
        if(n > 2 && message[0] == '!' && message[1] == '{') {
            int i;
            char cache[10];
            userlist_reset();
            memset(cache, 0, sizeof(cache));
            for(i = 2; i < strlen(message); i++) {
                if(message[i] != ',') {
                    cache[strlen(cache)] = message[i];
                }
                else {
                    userlist_add(cache);
                    memset(cache, 0, sizeof(cache));
                    i++; //skip the space
                }
            }
            userlist_add(cache);
            force_change = true;
        }
        else {
            add_message(message, 1, white, background_message);
        }
    }
    else {
        //connection lost
    }
}

int con_activate(void) {
    int n;
    struct sockaddr_in serv_addr;
   
    //initialise shit
    memset(&serv_addr, '0', sizeof(serv_addr));
    serv_addr.sin_family = AF_INET;
    serv_addr.sin_addr.s_addr = inet_addr("xxx.xxx.xxx.xxx");
    serv_addr.sin_port = htons(9125);

    chatls = socket(AF_INET, SOCK_STREAM, 0);
    if(chatls < 0)
    {
        return -1;
    }
    n = connect(chatls, (struct sockaddr*)&serv_addr, sizeof(serv_addr));
    if (n < 0)
    {
       return -2;
    }
    if(set_socket_nonblocking(chatls) == -1) {
        return -3;
    }

    send_handshake();
   
    return 0;
}

The function "add_message" is defined in another file, which simply prints out the message
 
  • Like
Reactions: spoonm and Gocario
Yeah, why not? The only problem is that my 3DS just broke. So i can't run Homebrew :(
Maybe if someone else could test for me?
If you don't have a 3DS to test it, the best thing to do is write platform independent code and once you're finished with the core you just write the interface for the 3DS
 

Site & Scene News

Popular threads in this forum