Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chat feature based on Adenovan's Rechat branch #12667

Merged
merged 27 commits into from
Mar 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
10e874c
PPSSPP early chat feature rebranched
adenovan Oct 21, 2016
bd2342a
Enable chat box
sum2012 Oct 21, 2016
08a1cc7
Add translation
sum2012 Oct 21, 2016
07b1d8b
pointer fix random crash & better substring logic
adenovan Oct 22, 2016
2874c6d
Oops it still random crashed destructor do the fix well
adenovan Oct 22, 2016
18525ea
Android Chat Support
adenovan Oct 23, 2016
5187b9f
Add New Chat Counter
adenovan Oct 24, 2016
f514b25
Windows CTRL + C Hotkey
adenovan Oct 25, 2016
20b289c
cmake buildfix
adenovan Oct 25, 2016
766373e
pointer and scroll fix
adenovan Oct 26, 2016
6b39018
Android chat empty after : fix
adenovan Oct 27, 2016
e17b57d
Add support OSK for windows
sum2012 Oct 27, 2016
fae8633
Build fix for Linux QT
sum2012 Oct 27, 2016
1241d53
Add translation of "You're in Offline Mode"
sum2012 Oct 27, 2016
6121dce
remove pointer and using update() should fix random crash (thanks Ukn…
adenovan Oct 31, 2016
624d1cd
chat screen & chat button position and hide ui on show chat
adenovan Dec 5, 2016
6706698
build fix
adenovan Dec 5, 2016
97a4d64
Rebased and fix the update scroll
adenovan Jun 7, 2017
8ec2d50
Add virtual key for opening chat
adenovan Jun 7, 2017
f5d5687
Quick Chat
adenovan Jul 6, 2017
4420719
Bug fix
adenovan Jul 8, 2017
f236ea1
group chat options and set enabled ptr
adenovan Aug 8, 2017
5382efd
Update ab.cmd
adenovan Aug 8, 2017
142e609
Merge branch 'rechat' of https://github.com/adenovan/amultios-ppsspp …
anr2me Mar 2, 2020
93b59af
Fix building errors
anr2me Mar 2, 2020
394194f
Fix chat color formatting
anr2me Mar 2, 2020
dc4df7d
Tweaked chatbox a little bit
anr2me Mar 2, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -838,6 +838,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 @@ -919,7 +919,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 @@ -384,6 +395,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