Skip to content

Commit

Permalink
Merge branch 'rechat' of https://github.com/ANR2ME/ppsspp into ANR2ME…
Browse files Browse the repository at this point in the history
…-rechat
  • Loading branch information
hrydgard committed Mar 8, 2020
2 parents 4b14b97 + dc4df7d commit 8f2a52c
Show file tree
Hide file tree
Showing 20 changed files with 661 additions and 18 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -842,6 +842,7 @@ list(APPEND NativeAppSource
UI/DiscordIntegration.cpp
UI/NativeApp.cpp
UI/BackgroundAudio.cpp
UI/ChatScreen.cpp
UI/DevScreens.cpp
UI/DisplayLayoutEditor.cpp
UI/DisplayLayoutScreen.cpp
Expand Down
1 change: 1 addition & 0 deletions Common/KeyMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,7 @@ const KeyMap_IntStrPair psp_button_names[] = {
{VIRTKEY_AXIS_RIGHT_Y_MIN, "RightAn.Down"},
{VIRTKEY_AXIS_RIGHT_X_MIN, "RightAn.Left"},
{VIRTKEY_AXIS_RIGHT_X_MAX, "RightAn.Right"},
{VIRTKEY_OPENCHAT, "OpenChat" },

{VIRTKEY_AXIS_SWAP, "AxisSwap"},
{VIRTKEY_DEVMENU, "DevMenu"},
Expand Down
1 change: 1 addition & 0 deletions Common/KeyMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ enum {
VIRTKEY_TEXTURE_REPLACE = 0x4000001A,
VIRTKEY_SCREENSHOT = 0x4000001B,
VIRTKEY_MUTE_TOGGLE = 0x4000001C,
VIRTKEY_OPENCHAT = 0x4000001D,
VIRTKEY_LAST,
VIRTKEY_COUNT = VIRTKEY_LAST - VIRTKEY_FIRST
};
Expand Down
10 changes: 9 additions & 1 deletion Core/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -920,7 +920,15 @@ static ConfigSetting controlSettings[] = {
static ConfigSetting networkSettings[] = {
ConfigSetting("EnableWlan", &g_Config.bEnableWlan, false, true, true),
ConfigSetting("EnableAdhocServer", &g_Config.bEnableAdhocServer, false, true, true),

ConfigSetting("EnableNetworkChat", &g_Config.bEnableNetworkChat, false, true, true),
ConfigSetting("ChatButtonPosition",&g_Config.iChatButtonPosition,BOTTOM_LEFT,true,true),
ConfigSetting("ChatScreenPosition",&g_Config.iChatScreenPosition,BOTTOM_LEFT,true,true),
ConfigSetting("EnableQuickChat", &g_Config.bEnableQuickChat, true, true, true),
ConfigSetting("QuickChat1", &g_Config.sQuickChat0, "Quick Chat 1", true, true),
ConfigSetting("QuickChat2", &g_Config.sQuickChat1, "Quick Chat 2", true, true),
ConfigSetting("QuickChat3", &g_Config.sQuickChat2, "Quick Chat 3", true, true),
ConfigSetting("QuickChat4", &g_Config.sQuickChat3, "Quick Chat 4", true, true),
ConfigSetting("QuickChat5", &g_Config.sQuickChat4, "Quick Chat 5", true, true),
ConfigSetting(false),
};

Expand Down
22 changes: 22 additions & 0 deletions Core/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,17 @@

extern const char *PPSSPP_GIT_VERSION;

enum ChatPositions {
BOTTOM_LEFT = 0,
BOTTOM_CENTER = 1,
BOTOM_RIGHT = 2,
TOP_LEFT = 3,
TOP_CENTER = 4,
TOP_RIGHT = 5,
CENTER_LEFT = 6,
CENTER_RIGHT = 7,
};

namespace http {
class Download;
class Downloader;
Expand Down Expand Up @@ -385,6 +396,17 @@ struct Config {
bool bEnableAdhocServer;
int iWlanAdhocChannel;
bool bWlanPowerSave;
bool bEnableNetworkChat;
//for chat position , moveable buttons is better than this
int iChatButtonPosition;
int iChatScreenPosition;

bool bEnableQuickChat;
std::string sQuickChat0;
std::string sQuickChat1;
std::string sQuickChat2;
std::string sQuickChat3;
std::string sQuickChat4;

int iPSPModel;
int iFirmwareVersion;
Expand Down
87 changes: 72 additions & 15 deletions Core/HLE/proAdhoc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ std::recursive_mutex peerlock;
SceNetAdhocPdpStat * pdp[255];
SceNetAdhocPtpStat * ptp[255];
uint32_t localip;
std::vector<std::string> chatLog;
std::string name = "";
std::string incoming = "";
std::string message = "";
bool chatScreenVisible = false;
bool updateChatScreen = false;
int newChat = 0;

int isLocalMAC(const SceNetEtherAddr * addr) {
SceNetEtherAddr saddr;
Expand Down Expand Up @@ -981,6 +988,45 @@ void freeFriendsRecursive(SceNetAdhocctlPeerInfo * node) {
free(node);
}

void sendChat(std::string chatString) {
SceNetAdhocctlChatPacketC2S chat;
auto n = GetI18NCategory("Networking");
chat.base.opcode = OPCODE_CHAT;
//TODO check network inited, check send success or not, chatlog.pushback error on failed send, pushback error on not connected
if (friendFinderRunning)
{
// Send Chat to Server
if (!chatString.empty()) {
//maximum char allowed is 64 character for compability with original server (pro.coldbird.net)
message = chatString.substr(0, 60); // 64 return chat variable corrupted is it out of memory?
strcpy(chat.message, message.c_str());
//Send Chat Messages
int chatResult = send(metasocket, (const char *)&chat, sizeof(chat), 0);
NOTICE_LOG(SCENET, "Send Chat %s to Adhoc Server", chat.message);
name = g_Config.sNickName.c_str();
chatLog.push_back(name.substr(0, 8) + ": " + chat.message);
if (chatScreenVisible) {
updateChatScreen = true;
}
}
}
else {
chatLog.push_back(n->T("You're in Offline Mode, go to lobby or online hall"));
if (chatScreenVisible) {
updateChatScreen = true;
}
}
}

std::vector<std::string> getChatLog() {
// this log used by chat screen
if (chatLog.size() > 50) {
//erase the first 40 element limit the chatlog size
chatLog.erase(chatLog.begin(), chatLog.begin() + 40);
}
return chatLog;
}

int friendFinder(){
// Receive Buffer
int rxpos = 0;
Expand Down Expand Up @@ -1024,13 +1070,6 @@ int friendFinder(){
}*/
}

// Send Chat Messages
//while(popFromOutbox(chat.message))
//{
// // Send Chat to Server
// sceNetInetSend(metasocket, (const char *)&chat, sizeof(chat), 0);
//}

// Wait for Incoming Data
int received = recv(metasocket, (char *)(rx + rxpos), sizeof(rx) - rxpos, 0);

Expand Down Expand Up @@ -1078,14 +1117,23 @@ int friendFinder(){
if (rxpos >= (int)sizeof(SceNetAdhocctlChatPacketS2C)) {
// Cast Packet
SceNetAdhocctlChatPacketS2C * packet = (SceNetAdhocctlChatPacketS2C *)rx;

// Fix for Idiots that try to troll the "ME" Nametag
if (strcasecmp((char *)packet->name.data, "ME") == 0) strcpy((char *)packet->name.data, "NOT ME");

// Add Incoming Chat to HUD
//printf("Receive chat message %s", packet->base.message);
DEBUG_LOG(SCENET, "Received chat message %s", packet->base.message);

NOTICE_LOG(SCENET, "Received chat message %s", packet->base.message);
incoming = "";
name = (char *)packet->name.data;
incoming.append(name.substr(0, 8));
incoming.append(": ");
incoming.append((char *)packet->base.message);
chatLog.push_back(incoming);
//im new to pointer btw :( doesn't know its safe or not this should update the chat screen when data coming
if (chatScreenVisible) {
updateChatScreen = true;
}
else {
if (newChat < 50) {
newChat += 1;
}
}
// Move RX Buffer
memmove(rx, rx + sizeof(SceNetAdhocctlChatPacketS2C), sizeof(rx) - sizeof(SceNetAdhocctlChatPacketS2C));

Expand All @@ -1107,7 +1155,16 @@ int friendFinder(){

// Add User
addFriend(packet);

incoming = "";
incoming.append((char *)packet->name.data);
incoming.append(" Joined ");
//do we need ip?
//joined.append((char *)packet->ip);
chatLog.push_back(incoming);
//im new to pointer btw :( doesn't know its safe or not this should update the chat screen when data coming
if (chatScreenVisible) {
updateChatScreen = true;
}
// Update HUD User Count
#ifdef LOCALHOST_AS_PEER
setUserCount(getActivePeerCount());
Expand Down
10 changes: 10 additions & 0 deletions Core/HLE/proAdhoc.h
Original file line number Diff line number Diff line change
Expand Up @@ -847,6 +847,16 @@ SceNetAdhocMatchingMemberInternal* addMember(SceNetAdhocMatchingContext * contex
*/
void addFriend(SceNetAdhocctlConnectPacketS2C * packet);

/**
* Send chat or get that
* @param std::string ChatString
*/
void sendChat(std::string chatString);
std::vector<std::string> getChatLog();
extern bool chatScreenVisible;
extern bool updateChatScreen;
extern int newChat;

/*
* Find a Peer/Friend by MAC address
*/
Expand Down
Loading

0 comments on commit 8f2a52c

Please sign in to comment.