| 1555 | |
| 1556 | |
| 1557 | bool cPlayer::LoadFromDisk() |
| 1558 | { |
| 1559 | LoadPermissionsFromDisk(); |
| 1560 | |
| 1561 | // Log player permissions, cause it's what the cool kids do |
| 1562 | LOGINFO("Player %s has permissions:", m_PlayerName.c_str() ); |
| 1563 | for( PermissionMap::iterator itr = m_ResolvedPermissions.begin(); itr != m_ResolvedPermissions.end(); ++itr ) |
| 1564 | { |
| 1565 | if( itr->second ) LOG(" - %s", itr->first.c_str() ); |
| 1566 | } |
| 1567 | |
| 1568 | AString SourceFile; |
| 1569 | Printf(SourceFile, "players/%s.json", m_PlayerName.c_str() ); |
| 1570 | |
| 1571 | cFile f; |
| 1572 | if (!f.Open(SourceFile, cFile::fmRead)) |
| 1573 | { |
| 1574 | // This is a new player whom we haven't seen yet, bail out, let them have the defaults |
| 1575 | return false; |
| 1576 | } |
| 1577 | |
| 1578 | AString buffer; |
| 1579 | if (f.ReadRestOfFile(buffer) != f.GetSize()) |
| 1580 | { |
| 1581 | LOGWARNING("Cannot read player data from file \"%s\"", SourceFile.c_str()); |
| 1582 | return false; |
| 1583 | } |
| 1584 | f.Close(); //cool kids play nice |
| 1585 | |
| 1586 | Json::Value root; |
| 1587 | Json::Reader reader; |
| 1588 | if (!reader.parse(buffer, root, false)) |
| 1589 | { |
| 1590 | LOGWARNING("Cannot parse player data in file \"%s\", player will be reset", SourceFile.c_str()); |
| 1591 | } |
| 1592 | |
| 1593 | Json::Value & JSON_PlayerPosition = root["position"]; |
| 1594 | if (JSON_PlayerPosition.size() == 3) |
| 1595 | { |
| 1596 | SetPosX(JSON_PlayerPosition[(unsigned int)0].asDouble()); |
| 1597 | SetPosY(JSON_PlayerPosition[(unsigned int)1].asDouble()); |
| 1598 | SetPosZ(JSON_PlayerPosition[(unsigned int)2].asDouble()); |
| 1599 | m_LastPosX = GetPosX(); |
| 1600 | m_LastPosY = GetPosY(); |
| 1601 | m_LastPosZ = GetPosZ(); |
| 1602 | m_LastFoodPos = GetPosition(); |
| 1603 | } |
| 1604 | |
| 1605 | Json::Value & JSON_PlayerRotation = root["rotation"]; |
| 1606 | if (JSON_PlayerRotation.size() == 3) |
| 1607 | { |
| 1608 | SetYaw ((float)JSON_PlayerRotation[(unsigned int)0].asDouble()); |
| 1609 | SetPitch ((float)JSON_PlayerRotation[(unsigned int)1].asDouble()); |
| 1610 | SetRoll ((float)JSON_PlayerRotation[(unsigned int)2].asDouble()); |
| 1611 | } |
| 1612 | |
| 1613 | m_Health = root.get("health", 0).asInt(); |
| 1614 | m_AirLevel = root.get("air", MAX_AIR_LEVEL).asInt(); |
nothing calls this directly
no test coverage detected